php - Select data from SQL database and display in table does not work -
i don't understand why isn't working, have been stuck on ages , tried lots of different alternatives, doesn't print data database.
at moment trying id print, want print of data in database (not including hash).
here code:
<!doctype html> <html> <head> <title>staroids leaderboard</title> </head> <body> <table border=1px> <thead> <tr> <td>name</td> <td>score</td> </tr> </thead> <tbody> <?php $connect = mysql_connect("localhost","root", "password"); if (!$connect) { die(mysql_error()); } mysql_select_db("staroids"); $results = mysql_query("select id scores"); while($row = mysql_fetch_array($results)) { $name = $row['id'] ?> <tr> <td><?php echo '$name'?></td> </tr> <?php } ?> </tbody> </table> </body> </html>
the image below shows looks in html:
this image shows database in local host , can see there lots of data, none of names seem print?!
correct syntax be
$name = $row['id']; //put ; here <?php echo $name;?> //remove quotes , put ;
select name db , can name then.it should be
$results = mysql_query("select id,name scores"); while($row = mysql_fetch_array($results)) { $name = $row['name']; ?> <td><?php echo $name;?></td>
and dont use mysql_*
functions due deprecated.instead use mysqli_*
functions or pdo
statements.
and @nedstark said use try die(mysql_error());
errors regarding mysql errors.
Comments
Post a Comment