但是我不知道如何在php中放置sql代码,有人能帮我吗?我知道它有点像SELECT * FROM form ORDER BY 'Klant_id' ASC LIMIT 1
<html>
<header>
<link rel="stylesheet" href="css/style.css" type="text/css" />
</header>
<body>
<?php
//makes an connection to the db
mysql_connect("localhost", "root", '') or die(mysql_error());
mysql_select_db('databaseimage') or die(mysql_error());
$data = mysql_query("SELECT * FROM form ORDER BY 'Klant_id' ASC LIMIT 1")
or die(mysql_error());
echo "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data))
{
echo "<tr>";
echo "<th>surname:</th> <td>".$info['Surname'] . "</td> ";
echo "<th>insertion:</th> <td>".$info['Insertion'] . "</td> ";
echo "<th>initials:</th> <td>".$info['Initials'] . "</td> ";
echo "<th>name:</th> <td>".$info['Name'] . "</td> ";
echo "<th>sex:</th> <td>".$info['Sex'] . "</td> ";
echo "<th>adress:</th> <td>".$info['Adress'] . "</td> ";
echo "<th>postcode:</th> <td>".$info['Postcode'] . "</td> ";
echo "<th>location:</th> <td>".$info['Location'] . "</td> ";
echo "<th>private phone:</th> <td>".$info['Private_phone'] . "</td> ";
echo "<th>mobile phone:</th> <td>".$info['Mobile_phone'] . "</td> ";
echo "<th>work phone:</th> <td>".$info['Work_phone'] . "</td> ";
echo "<th>private email:</th> <td>".$info['Private_email'] . "</td> ";
echo "<th>work email:</th> <td>".$info['Work_email'] . "</td> ";
}
Print "</table>";
?>
</body>
</html>发布于 2012-09-03 15:20:03
不要用单引号将列Klant_ID括起来。单引号和反引号有很大的不同。
SELECT *
FROM form tablename
ORDER BY Klant_id DESC
LIMIT 1或
SELECT *
FROM form tablename
ORDER BY `Klant_id` DESC
LIMIT 1差异:
Single quotes (‘)应该用于字符串值,就像在VALUES()列表中一样。
MySQL也支持对字符串值使用Double quotes,但其他RDBMS更广泛地接受单引号,因此使用单引号而不是双引号是一个好习惯。
发布于 2012-09-03 14:51:44
当你有auto_increment的主键时,你应该使用DESC降序来获取它。以便获取最后插入的记录。
尝尝这个。
SELECT * FROM form ORDER BY `Klant_id` DESC LIMIT 1发布于 2012-09-03 15:16:00
如果您有设置了auto_increment的主键。你可以用两种方法来完成
First
SELECT * FROM form WHERE Klant_id=(select MAX(Klant_id) FROM form)第二个
SELECT * FROM form ORDER BY Klant_id DESC LIMIT 1;https://stackoverflow.com/questions/12243169
复制相似问题