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:

enter image description here

this image shows database in local host , can see there lots of data, none of names seem print?!

enter image description here

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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -