Carbon Posted August 17, 2011 Share Posted August 17, 2011 My MySQL Version is 5.1 and I am getting no errors. I am trying to generate a leaderboards and then displaying the output in a HTML table, here is my code: <?php //I removed these but in the actual script they are working /** MySQL database name */ define('DB_NAME', ''); /** MySQL database username */ define('DB_USER', ''); /** MySQL database password */ define('DB_PASSWORD', ''); /** MySQL hostname */ define('DB_HOST', ''); $table = "highscores"; // Initialization $conn = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD); mysql_select_db(DB_NAME, $conn); // Error checking if(!$conn) { die('Error: ' . mysql_error()); } $type = isset($_GET['type']) ? $_GET['type'] : "global"; $offset = isset($_GET['offset']) ? $_GET['offset'] : "0"; $count = isset($_GET['count']) ? $_GET['count'] : "10"; $sort = isset($_GET['sort']) ? $_GET['sort'] : "Credits DESC"; // Localize the GET variables $user = isset($_GET['username']) ? $_GET['username'] : ""; $time = isset($_GET['time']) ? $_GET['time'] : ""; $videos = isset($_GET['videos']) ? $_GET['videos'] : ""; $credits = isset($_GET['credits']) ? $_GET['credits'] : ""; // Protect against sql injections $type = mysql_real_escape_string($type); $offset = mysql_real_escape_string($offset); $count = mysql_real_escape_string($count); $sort = mysql_real_escape_string($sort); $user = mysql_real_escape_string($user); $time = mysql_real_escape_string($time); $videos = mysql_real_escape_string($videos); $credits = mysql_real_escape_string($credits); // Build the sql query $sql = "SELECT * FROM $table WHERE "; switch($type) { case "global": $sql .= "1 "; break; case "username": $sql .= "Username = '$user' "; break; case "videos": $sql .= "Videos = '$videos' "; break; case "time": $sql .= "Time = '$time' "; break; case "credits": $sql .= "Credits = '$credits' "; break; } $sql .= "ORDER BY $sort "; $sql .= "LIMIT $offset,$count "; $result = mysql_query($sql,$conn); if(!$result) { die("Error retrieving scores " . mysql_error()); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/> </head> <body> <center> <?php // Display the table echo '<table style="width:25%"> <table border="1"> <thead> <tr> <th>Username</th> <th>Time Ran</th> <th>Videos Watched</th> <th>Credits Gained</th> </tr> </thead> <tbody>'; while ($row = mysql_fetch_object($result)) { echo '<tr> <td> '.$row->username.' </td> <td> '.$row->time.' </td> <td> '.$row->videos.' </td> <td> '.$row->credits.' </td> </tr>'; } echo '</tbody> </table>'; mysql_free_result($result); mysql_close($conn); ?> </center> </body> </html> I have 3 different entries I inserted into the database but it is generating nothing: I am not quite sure what's wrong and if anyone can help me that would be great, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/245015-html-table-not-displaying-anything/ Share on other sites More sharing options...
fenway Posted August 17, 2011 Share Posted August 17, 2011 Don't post your entire script. Echo the $sql variable. Quote Link to comment https://forums.phpfreaks.com/topic/245015-html-table-not-displaying-anything/#findComment-1258523 Share on other sites More sharing options...
Carbon Posted August 17, 2011 Author Share Posted August 17, 2011 Don't post your entire script. Echo the $sql variable. Sorry, it's not letting me edit it now though. Also, is this what you're talking about? SELECT * FROM highscores WHERE 1 ORDER BY Credits DESC LIMIT 0,10 Quote Link to comment https://forums.phpfreaks.com/topic/245015-html-table-not-displaying-anything/#findComment-1258529 Share on other sites More sharing options...
Carbon Posted August 17, 2011 Author Share Posted August 17, 2011 Update since I cannot edit previous posts: If I add more entries to the database, more rows will appear but containing nothing: Quote Link to comment https://forums.phpfreaks.com/topic/245015-html-table-not-displaying-anything/#findComment-1258534 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.