Jump to content

R0CKY

Members
  • Posts

    39
  • Joined

  • Last visited

Posts posted by R0CKY

  1. It works fantastic now, the result is really great, but the code has turned out a bit over the top - and it's not even finished yet... take a look..

    [quote] $cat = ($file->file_catid);

      switch($cat) {
      case 15:
      case 16:
      case 17:
      case 18:
      case 19:
      case 20:
      case 21:
      case 22:
      case 23:
      case 24:
      case 28:
      case 30:
      case 31:
      case 43:
        echo "<img src=\"../images_site/mods-gr1.jpg\" title=\"GR1\" />";
        break;
      case 27:
      case 33:
      case 44:
      case 41:
      case 36:
      case 37:
      case 39:
      case 40:
      case 34:
      case 35:
      case 38:
      case 42:
      case 45:
        echo "<img src=\"../images_site/mods-graw1.jpg\" title=\"GRAW1\" />";
        break;
      default:
        echo "<img src=\"../images_site/mods-gen.jpg\" title=\"GEN\" />";

    //Add additional cases

    }[/quote]

    Can anyone give me some (beginner) help with perhaps doing this by array instead?

    Many thanks.
  2. I like the array idea, but don't know how to make a category array as suggested, so I went with the longer switch code, but it's not working, there is no output from the entire page with the following code inserted. If I comment out the switch section, the page works again. 

    [quote] $cat = ($file->file_catid);

      switch($cat) {
      case: 1
      case: 2
      case: 10
      case: 14
        echo "<img src=\"../images_site/mods-gr1.jpg\" title=\"GR1\" />";
        break;
      case: 3
      case: 7
      case: 11
      case: 12
        echo "<img src=\"../images_site/mods-graw1.jpg\" title=\"GRAW1\" />";
        break;
      default:
        echo "<img src=\"../images_site/mods-gen.jpg\" title=\"GEN\" />";

    //Add additional cases

    }[/quote]

    I really can't see what is wrong with the above, I even tried changing the img src code to echo simple piece of text, and there was still no output at all.

    Any ideas?  :-\
  3. [quote author=mjdamato link=topic=121048.msg497098#msg497098 date=1167949017]
    Where is $category coming from?
    [/quote]

    Yes it is coming from the database, as you can see in the following loop. At the moment I am simply getting the loop to echo the category (as a number), but as per my request above, I am now trying to assign a relevant image and have it appear instead.

    [quote]
    $i = 1;
    while ($file = mysql_fetch_object($result)) {
    [b]$cat = ($file->file_catid);[/b]
    $line = str_replace("{number}", $i, $template);
    $line = str_replace("{filelink}", "$config[3]/pafiledb.php?action=file&id=$file->file_id", $line);
    $line = str_replace("{filename}", trimlen($file->file_name), $line);
        //$line = str_replace("{filename}", $file->file_name, $line);
    if ($list == "newest") {  $infoline = str_replace("{date}", date("n/j/y", $file->file_time), $info); }
    if ($list == "downloads") {$infoline = str_replace("{downloads}", $file->file_dls , $info); }
    if ($list == "rating") {
    $ntv = $file->file_totalvotes - 1;
    $infoline = str_replace("{rating}", @round($file->file_rating/$ntv,2), $info);
    $infoline = str_replace("{votes}", $ntv, $infoline);
    }
    $line = str_replace("{info}", $infoline, $line);
    [b]echo $cat;[/b]
    echo $line;
    $i++;
    }
    ?>
    [/quote]

    I am new to this and don't really understand the code you posted but I think I understand how a switch works, and I'll try doing it with multiple values as you suggested.

    Thanks.
  4. PHP clueless here...

    What is the best way to achieve this requirement?

    Check a database field and retrieve a value $category
    echo an image depending the value of $category

    The value of $category can be anything from 1-40

    For example

    If $category = 1,2,10 or 14 then echo image catyellow.gif
    If $category = 3,7,11 or 12 then echo image catred.gif
    If $category = 20,21,31 or 32 then echo image catblue.gif

    etc etc

    Is this a case for using the [b]switch[/b] command, or is there another (clever) way to achieve the same thing but with less code. For example perhaps by naming the gifs to accord with the $category values...?

    Thanks for any hints.
  5. Thank you Jesi, I feel we are getting closer, but I still get no output  :(

    Here is the full page, with the added code in bold - something of which is stopping the page from executing.

    [quote]<style type="text/css">
    A:link {text-decoration: underline; font-weight: bold; color:#CCCCCC} A:visited {text-decoration: underline; font-weight: bold;; color: #CCCCCC} A:active {text-decoration: none;} A:hover {text-decoration: underline; color:#00FF33;
    }
    body {
    background-color: black;
    font-family: Tahoma;
    font-size: 8pt;
    color: 00CC00
    }
    </style>
    <?php
    [b]function trimlen($string) {
      if (len($string) > 20) {
        $string = substr($string,0,17).'...';
      }
      return $string;
    }[/b]
    /*
      paFileDB 3.1
      ©2001/2002 PHP Arena
      Written by Todd
      todd@phparena.net
      http://www.phparena.net
      Keep all copyright links on the script visible
      Please read the license included with this script for more information.
    */
    $path = "**removed**";
    //This is the full system path to your paFileDB folder. You will need to obtain this information from a phpinfo.php file, or from your host.
    $show = "20"; //How many files do you want to show on the list
    $template = "<span class=\"style1\"> {number}.<a href=\"{filelink}\">{filename} </a></span><br>";
    //Template for each line.
    //Don't modify anything below this line.
    require $path. "/includes/mysql.php";
    $pafiledb_sql->connect($db);
    $config = $pafiledb_sql->query($db,"SELECT * FROM $db[prefix]_settings",1);
    switch ($list) {
    case newest:
    $result = $pafiledb_sql->query($db, "SELECT * FROM $db[prefix]_files ORDER BY file_time DESC LIMIT 0,$show ", 0);
    $info = "Added on {date}";
    break;
    case downloads:
    $result = $pafiledb_sql->query($db, "SELECT * FROM $db[prefix]_files ORDER BY file_dls DESC LIMIT 0,$show ", 0);
    $info = "{downloads}";
    break;
    case rating:
    $result = $pafiledb_sql->query($db, "SELECT * FROM $db[prefix]_files ORDER BY file_rating/(file_totalvotes - 0) DESC LIMIT 0,$show", 0);
    $info = "{rating}/10 - {votes} Votes";
    break;
    default:
    die("You didn't select the type of list to show. Please see the paFileDB manual for more information");
    break;
    }
    $i = 1;
    while ($file = mysql_fetch_object($result)) {
    $line = str_replace("{number}", $i, $template);
    $line = str_replace("{filelink}", "$config[3]/pafiledb.php?action=file&id=$file->file_id", $line);
    [b]$line = str_replace("{filename}", trimlen($file->file_name), $line);[/b]
        //$line = str_replace("{filename}", $file->file_name, $line);
    if ($list == "newest") {  $infoline = str_replace("{date}", date("n/j/y", $file->file_time), $info); }
    if ($list == "downloads") {$infoline = str_replace("{downloads}", $file->file_dls , $info); }
    if ($list == "rating") {
    $ntv = $file->file_totalvotes - 1;
    $infoline = str_replace("{rating}", @round($file->file_rating/$ntv,2), $info);
    $infoline = str_replace("{votes}", $ntv, $infoline);
    }
    $line = str_replace("{info}", $infoline, $line);
    echo $line;
    $i++;
    }
    ?>[/quote]

  6. Look at the security code I had to try and read to sign up here  ???

    Is it just me, or is that 1st character nothing like an "r", and how about that lower case "t"

    [img]http://www.ghostrecon.net/images-forums/capcha.jpg[/img]

    rEtgp

    Dang spammers making us decent folks jump through hoops  :P
  7. That worked Thorpe, thank you.

    What is actually happening with this piece of code?

    [b]$file->file_name[/b]

    Is it a new string being created, and it's value coming from a sql field?

    If anyone has the inclination, what I ultimately wanted to do with the output $line, was have it check the length of {filename} and if it was over 20, then trim it to 17, and add a string of three periods "...", that would be very cool.

    Thanks again.
  8. Hmmm, your code has $filename, but my code does not have the $, it has {filename} - will it work the same, so my new code would change from

      $line = str_replace([b]"{filename}"[/b], $file->file_name, $line);

    to
      $shortFile = substr($filename, 0, 20);
      $line = str_replace[b]($shortfile[/b], $file->file_name, $line);

    I have a feeling that's not right...?
  9. I'm trying to edit an existing php page so that it trims a string to 20 characters, but I cannot figure out how to do it (n00b).

    The relevant loop is below..

    [quote]
    $show = "20";
    $template = "<span class=\"style1\"> {number}.<a href=\"{filelink}\">{filename} </a></span><br>";
    $i = 1;
    while ($file = mysql_fetch_object($result)) {
    $line = str_replace("{number}", $i, $template);
    $line = str_replace("{filelink}", "$config[3]/pafiledb.php?action=file&id=$file->file_id", $line);
    $line = str_replace("{[b]filename[/b]}", $file->file_name, $line);
    if ($list == "newest") {  $infoline = str_replace("{date}", date("n/j/y", $file->file_time), $info); }
    if ($list == "downloads") {$infoline = str_replace("{downloads}", $file->file_dls , $info); }
    if ($list == "rating") {
    $ntv = $file->file_totalvotes - 1;
    $infoline = str_replace("{rating}", @round($file->file_rating/$ntv,2), $info);
    $infoline = str_replace("{votes}", $ntv, $infoline);
    }
    $line = str_replace("{info}", $infoline, $line);
    echo $line;
    $i++;
    }[/quote]

    The part I need trimmed back to 20 chars is the filename, so that when the $line variable is output to the browser, the filename part is no longer than 20 chars - but I am not clued up on PHP so although I know I need to use SUBSTR, I do not know how to apply it in the above situation.

    Any help would be much appreciated.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.