tecmeister Posted February 16, 2008 Share Posted February 16, 2008 Hi everyone, How do i create a Table at the end of a quiz? I want it goes by the highest score. Thank for your help. tecmeister Link to comment https://forums.phpfreaks.com/topic/91452-quiz-table/ Share on other sites More sharing options...
ratcateme Posted February 17, 2008 Share Posted February 17, 2008 i am assuming you are storing peoples scores in a database then you could have a script like this <?php mysql_connect(); mysql_select_db('quiz'); $result=mysql_query('SELECT * FROM `quiz` ORDER BY `score`'); echo '<table>'; while($row=mysql_fetch_array($result)){ echo "<tr> <td>{$row['name']}</td> <td>{$row['score']}</td> </tr>"; } echo '</table>'; ?> Scott. Link to comment https://forums.phpfreaks.com/topic/91452-quiz-table/#findComment-468534 Share on other sites More sharing options...
tecmeister Posted February 17, 2008 Author Share Posted February 17, 2008 I out in the code but im getting this error. Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'nurevolution.co.'@'localhost' (using password: NO) in /home/sites/nurevolution.co.uk/public_html/quiz/adults easy/adults easy finsih.php on line 18 Could not connect:Access denied for user 'nurevolution.co.'@'localhost' (using password: NO) So i tried this: <?php $dbhost = "localhost"; $dbname = "*******"; $dbuser = "********"; $dbpass = "********"; mysql_connect ($dbusername,$dbscore)or die("Could not connect:".mysql_error()); mysql_select_db('adults easy'); $result=mysql_query('SELECT * FROM `adults easy` ORDER BY `score`'); echo '<table>'; while($row=mysql_fetch_array($result)){ echo "<tr> <td>{$row['username']}</td> <td>{$row['score']}</td> </tr>"; } echo '</table>'; ?> Link to comment https://forums.phpfreaks.com/topic/91452-quiz-table/#findComment-468572 Share on other sites More sharing options...
ratcateme Posted February 17, 2008 Share Posted February 17, 2008 I am not sure where your mysql_connect vars are coming form but i would suggest it should look like this mysql_connect ($gbhost,$dbuser,$dbpass)or die("Could not connect:".mysql_error()); Scott. Link to comment https://forums.phpfreaks.com/topic/91452-quiz-table/#findComment-468649 Share on other sites More sharing options...
tecmeister Posted February 17, 2008 Author Share Posted February 17, 2008 O yeah. Bloody hell. I have got to stop staying till 3 in the morning. Im a total newbie. Link to comment https://forums.phpfreaks.com/topic/91452-quiz-table/#findComment-468690 Share on other sites More sharing options...
tecmeister Posted February 17, 2008 Author Share Posted February 17, 2008 I have entered the script that you told me to and there is nufin on the screen. Link to comment https://forums.phpfreaks.com/topic/91452-quiz-table/#findComment-468698 Share on other sites More sharing options...
AndyB Posted February 17, 2008 Share Posted February 17, 2008 $dbhost = "localhost"; $dbname = "*******"; $dbuser = "********"; $dbpass = "********"; mysql_connect ($dbusername,$dbscore) or die("Could not connect:".mysql_error()); Take a careful look at your code. Is $dbusername defined? Is $dbscore defined? Neither is! Link to comment https://forums.phpfreaks.com/topic/91452-quiz-table/#findComment-468839 Share on other sites More sharing options...
ratcateme Posted February 17, 2008 Share Posted February 17, 2008 are you sure you are selecting the DB i would recomend changing the select_db line to mysql_select_db($dbname) or die("Could not select database:".mysql_error()); also check the source to see it <table> and </table> are being outputted. Scott. Link to comment https://forums.phpfreaks.com/topic/91452-quiz-table/#findComment-468961 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.