Small project: Troubleshoot PHP

Discussion in 'Programming' started by myfrogger, Jun 27, 2007.

  1. #1
    Domain: www [.] start free games [.] com
    (Please refrain from posting the domain in this forum. I don't want the bots to pick it up.)

    Problem: The PHP script doesn't create URL links correctly for the games under the "Most Popular Games" category. You'll see from the other links that the URL should be created using gID and gName.

    The links are redirecting correctly (so when you click it loads the right game) but the naming of the URL is not. The gID appears correctly but the gName/$fname does not.

    If you need any other part of the code or want me to define some variables, let me know. Please post your price and if your offer is accepted, I will pay you via paypal. THANKS

    htaccess Rewrite rule I'm using:
    RewriteRule ^game/([0-9]*)/(.*)\.html$ game.php?gId=$1&fname=$2 [L,NC]
    Code (markup):
    Here is the buggy script:
    <?php
    include "conn.php";
      $query_count    = "SELECT * FROM games";
      $result_count   = mysql_query($query_count,$db) or die (mysql_error()); 
      $totalrows      = mysql_num_rows($result_count); //line 65     
    
    $query  = "SELECT * FROM games  ORDER BY score DESC LIMIT 4";
    
    
    $result = mysql_query($query,$db) or die("Error: " . mysql_error());    
    $datas = mysql_fetch_array($result);
    
    $fname = str_replace(" ","-",$datas[gName]);
    $gamecategory1 = "Most Popular Games";
    $game1="<table height ='338' cellpadding='0' cellspacing='2'>";
    do { 
    $game1 .="<tr><td height='70' valign='top'><a href = '$siteurl/game/$datas[gId]/$fname.html'>
    <img src='$siteurl/thumbnails/$datas[gThumb]' alt='$datas[gName]' width='60' height='60'  align='left'></a></td><td valign='top'><a href = '$siteurl/game/$datas[gId]/$fname.html'><u><font color='000000' size='1'>$datas[gName]</a></font></u><font size='1'><br> <span>$datas[gDescription].</span> Rating($datas[points])
    </font></td></tr>";
       }	
    while ($datas = mysql_fetch_array($result));
    $game1.="</table>";
    ?>
    PHP:
     
    myfrogger, Jun 27, 2007 IP
  2. w3bmistress

    w3bmistress Well-Known Member

    Messages:
    145
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    Looks like a simple error.. but I will need to see more of the script to be sure... I can do this for $10 if you like. If it's more involved it will cost more, but I don't think it will. Send me a PM if you're interested.
     
    w3bmistress, Jun 27, 2007 IP
  3. smellynose

    smellynose Peon

    Messages:
    90
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    It looks like you're overwriting your array $datas and you are using the variable $fname which is declared outside of the loop, so it always stays the same.

    Try this:
    
    include "conn.php";
      $query_count    = "SELECT * FROM games";
      $result_count   = mysql_query($query_count,$db) or die (mysql_error()); 
      $totalrows      = mysql_num_rows($result_count); //line 65     
    
    $query  = "SELECT * FROM games  ORDER BY score DESC LIMIT 4";
    
    $result = mysql_query($query,$db) or die("Error: " . mysql_error());
    
    $gamecategory1 = "Most Popular Games";
    $game1 = "<table height ='338' cellpadding='0' cellspacing='2'>";
    
    while($datas = mysql_fetch_array($result)) {
    $fname = str_replace(" ","-",$data['gName']);
          $game1 .= <<<HTML
    <tr><td height='70' valign='top'><a href = '$siteurl/game/{$datas['gId']}/$fname.html'>
    <img src='$siteurl/thumbnails/{$datas['gThumb']}' alt='{$datas['gName']}' width='60' height='60'  align='left'></a></td><td valign='top'><a href = '$siteurl/game/{$datas['gId']}/$fname.html'><u><font color='000000' size='1'>{$datas['gName']}</a></font></u><font size='1'><br> <span>{$datas['gDescription']}.</span> Rating({$datas['points']})
    </font></td></tr>
    HTML;
    }
    $game1 .= "</table>";
    
    Code (markup):
     
    smellynose, Jun 27, 2007 IP
  4. daman371

    daman371 Peon

    Messages:
    121
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #4
    You are refetching the data from the query which isn't necessary. I'm also not sure if the data is being outputted because it is just being stored in the variable named game1. I'll just assume that the data is output somewhere else in the script. Here is the code that should work. I also took and made it where the queries aren't variables.

    
    <?php
    include "conn.php";
      $result_count   = mysql_query("SELECT * FROM games",$db) or die (mysql_error());
      $totalrows      = mysql_num_rows($result_count); //line 65     
    
    
    $result = mysql_query("SELECT * FROM games  ORDER BY score DESC LIMIT 4",$db) or die("Error: " . mysql_error());   
    $datas = mysql_fetch_array($result);
    
    $gamecategory1 = "Most Popular Games";
    $game1="<table height ='338' cellpadding='0' cellspacing='2'>";
    while ($datas = mysql_fetch_array($result))
    {
    $fname = str_replace(" ","-",$datas['gName']);
    $game1 .="<tr><td height='70' valign='top'><a href = '$siteurl/game/$datas[gId]/$fname.html'>
    <img src='$siteurl/thumbnails/$datas[gThumb]' alt='$datas[gName]' width='60' height='60'  align='left'></a></td><td valign='top'><a href = '$siteurl/game/$datas[gId]/$fname.html'><u><font color='000000' size='1'>$datas[gName]</a></font></u><font size='1'><br> <span>$datas[gDescription].</span> Rating($datas[points])
    </font></td></tr>";
    }
    $game1.="</table>";
    ?>
    Code (markup):
     
    daman371, Jun 27, 2007 IP
  5. myfrogger

    myfrogger Well-Known Member

    Messages:
    439
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    110
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #5
    Thanks daman371! That fixed it! I PMed you.

    The game1 variable is requested in the index.php file so that it can list this new category along with the other categories. Thanks again!
     
    myfrogger, Jun 27, 2007 IP