怎样利用php获取数据库中指定的记录
1个回答
展开全部
这是PHP获取数据库信息的代码 希望能给你带来启发
<?php
$conn=mysql_connect("localhost","root","");
$select=mysql_select_db("books",$conn);
$query="insert into computers(name,price,publish_data) ";
$query.="values('JSP',28.00,'2008-11-1')";
$query="select * from computers";
$result=mysql_query($query);
//以下是使用mysql_result()函数来获取到查询结果
$num=mysql_num_rows($result);
for($rows_count=0;$rows_count<$num;$rows_count++){
echo "书名:".mysql_result($result,$rows_count,"name");
echo "价格:".mysql_result($result,$rows_count,"price");
echo "出版日期:".mysql_result($result,$rows_count,"publish_data")."<br>";
}
//以下是使用mysql_fetch_row()函数来获取到查询结果
while($row=mysql_fetch_row($result))
{
echo "书号:".$row[0]."<br>";
echo "书名:".$row[1]."<br>";
echo "价格:".$row[2]."<br>";
echo "出版日期:".$row[3]."<br>";
echo "<br>";
}
//以下是使用mysql_fetch_array()函数来获取到查询结果
while($row=mysql_fetch_array($result))
{
echo "书号:".$row[0]."<br>";
echo "书名:".$row[1]."<br>";
echo "价格:".$row["price"]."<br>";
echo "出版日期:".$row["publish_data"]."<br>";
echo "<br>";
}
//以下是使用mysql_fetch_object()函数来获取到查询结果
while($row=mysql_fetch_object($result))
{
echo "书号:".$row->id."<br>";
echo "书名:".$row->name."<br>";
echo "价格:".$row->price."<br>";
echo "出版日期:".$row->publish_data."<br>";
echo "<br>";
}
?>
<?php
$conn=mysql_connect("localhost","root","");
$select=mysql_select_db("books",$conn);
$query="insert into computers(name,price,publish_data) ";
$query.="values('JSP',28.00,'2008-11-1')";
$query="select * from computers";
$result=mysql_query($query);
//以下是使用mysql_result()函数来获取到查询结果
$num=mysql_num_rows($result);
for($rows_count=0;$rows_count<$num;$rows_count++){
echo "书名:".mysql_result($result,$rows_count,"name");
echo "价格:".mysql_result($result,$rows_count,"price");
echo "出版日期:".mysql_result($result,$rows_count,"publish_data")."<br>";
}
//以下是使用mysql_fetch_row()函数来获取到查询结果
while($row=mysql_fetch_row($result))
{
echo "书号:".$row[0]."<br>";
echo "书名:".$row[1]."<br>";
echo "价格:".$row[2]."<br>";
echo "出版日期:".$row[3]."<br>";
echo "<br>";
}
//以下是使用mysql_fetch_array()函数来获取到查询结果
while($row=mysql_fetch_array($result))
{
echo "书号:".$row[0]."<br>";
echo "书名:".$row[1]."<br>";
echo "价格:".$row["price"]."<br>";
echo "出版日期:".$row["publish_data"]."<br>";
echo "<br>";
}
//以下是使用mysql_fetch_object()函数来获取到查询结果
while($row=mysql_fetch_object($result))
{
echo "书号:".$row->id."<br>";
echo "书名:".$row->name."<br>";
echo "价格:".$row->price."<br>";
echo "出版日期:".$row->publish_data."<br>";
echo "<br>";
}
?>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询