[英]MySQL result in PHP by ID
How can i display something out of my databse by an ID number? 如何通过ID号显示数据库中的某些内容?
I already can get the data out of the database by searching the row 'content' but i want to get it by an ID number. 我已经可以通过搜索“内容”行从数据库中获取数据,但是我想通过ID号获取它。
I have three rows in my database table: ID, pagename and content. 我的数据库表中有三行:ID,页面名和内容。
Here is the code that i already have for getting the data: 这是我已经拥有的用于获取数据的代码:
<?php
$con=mysqli_connect("localhost","jordyyd108_mario","testdb","jordyyd108_mario");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM pages");
while($row = mysqli_fetch_array($result)) {
echo $row['content'] ;
}
mysqli_close($con);
?>
Thanks! 谢谢!
use WHERE
clause and pass your id try 使用
WHERE
子句并传递您的id尝试
mysqli_query($con,"SELECT * FROM pages WHERE ID = '2'");
or pass a variable 或传递一个变量
mysqli_query($con,"SELECT * FROM pages WHERE ID = '$id'");
您可以使用WHERE:-
$result = mysqli_query($con,"SELECT * FROM pages where id = 1");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.