简体   繁体   中英

Display mysql_query result in PHP within MYSQL

I would like to know how can I display my MySQL result in PHP using tables. I have done a lot of research in this question. However I didn't find a way to solve my question. Here's my code.

<html>
<head>
</head>
<body>
<?php
$con = mysql_connect("localhost","root","123456");
if (!$con) {
die("Cannot Connect: " . mysql_error());
}
mysql_select_db("androidlogin",$con);
$sql = "select id, speed, distance FROM result";
$data = mysql_query($sql,$con);
echo "<table border=1>
<tr>
<th>ID</th>
<th>Speed</th>
<th>Distance</th>
</tr>";
while($record = mysql_fetch_array($data)){
echo "<tr>";
echo "<td>" . $record['ID'] . "</td>";
echo "<td>" . $record['Speed'] . "</td>";
echo "<td>" . $record['Distance'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_close($con);

?>
</body>
</html> 

It seems that it does not having any problems or I'm just too bad in it.

The output of the web: http://tinypic.com/r/2hdnypd/9

By the way, this code will be change a bit so that it will becomes leaderboard. And I have another problem, how should I do if I want to see where my record ranked, while the code $sql = "select users.username, result.speed, result.distance FROM result, users where result.id = users.id order by result.speed desc limit 10"; ?

Your db columns are id,speed and distance but while fetching records and displaying you are using it as ID, Speed and Distance.

So please change this part:

while($record = mysql_fetch_array($data)){
echo "<tr>";
echo "<td>" . $record['id'] . "</td>";
echo "<td>" . $record['speed'] . "</td>";
echo "<td>" . $record['distance'] . "</td>";
echo "</tr>";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM