主题:请教 还是数据库问题 谢谢
下面的程序有点长,麻烦朋友们给看一下,帮我找出无法获得查询输出的原因,谢谢!
运行结果是:
1:connect successfully!
2:select db successfully!
3:select table successfully!
接着是5个warning,说那几个函数 supplied argument is not a valid MySQL result resource 。
<?php
//1。连接数据库服务器 语句参考p88库级操作
$connection = mysql_connect ("localhost", "mydb", "mypsw");
if(!$connection)
echo "1:connect failed!<br>";
else
echo "1:connect successfully!<br>";
//2。选择数据库 语句参考p88库级操作
$select_db=mysql_select_db("mydb", $connection);
if(!$select_db)
echo "2:select db failed!<br>";
else
echo "2:select db successfully!<br>";
//3。查询数据 语句参考p92
$query="SELECT * FROM Computers ";
$query.="WHERE price >= 20";
//echo $query."<br>";
$result=mysql_query($query,$connection);
if(!$query)
echo "3:select table failed!<br>";
else
echo "3:select table successfully!<br>";
//4。用mysql_fetch_row()获得数据,并输出,p93
while($row=mysql_fetch_row($result)) //这里warning
{
echo "4:书名:".$row[1]."<br>";
echo "4:价格:".$row[2]."<br>";
echo "4:出版日期:".$row[3]."<br>";
echo "<br>";
}
//5.用mysql_result获得数据,并输出
for($rows_count=0;$rows_count<1;$rows_count++)
{
echo "5:书名:".mysql_result($result,$rows_count,"name")."<br>"; //这里warning
echo "5:价格:".mysql_result($result,$rows_count,"price")."<br>";//warning
echo "5:出版日期:".mysql_result($result,$rows_count,"publish_date");//warning
echo "<br>";
}
//6.mysql_fetch_array()获得数据,并输出
while($row=mysql_fetch_array($result)) //这里warning
{
echo "6:书名:".$row[1]."<br>";
echo "6:价格:".$row["price"]."<br>";
echo "6:出版日期:".$row["publish_date"]."<br>";
echo "<br>";
}
?>
运行结果是:
1:connect successfully!
2:select db successfully!
3:select table successfully!
接着是5个warning,说那几个函数 supplied argument is not a valid MySQL result resource 。
<?php
//1。连接数据库服务器 语句参考p88库级操作
$connection = mysql_connect ("localhost", "mydb", "mypsw");
if(!$connection)
echo "1:connect failed!<br>";
else
echo "1:connect successfully!<br>";
//2。选择数据库 语句参考p88库级操作
$select_db=mysql_select_db("mydb", $connection);
if(!$select_db)
echo "2:select db failed!<br>";
else
echo "2:select db successfully!<br>";
//3。查询数据 语句参考p92
$query="SELECT * FROM Computers ";
$query.="WHERE price >= 20";
//echo $query."<br>";
$result=mysql_query($query,$connection);
if(!$query)
echo "3:select table failed!<br>";
else
echo "3:select table successfully!<br>";
//4。用mysql_fetch_row()获得数据,并输出,p93
while($row=mysql_fetch_row($result)) //这里warning
{
echo "4:书名:".$row[1]."<br>";
echo "4:价格:".$row[2]."<br>";
echo "4:出版日期:".$row[3]."<br>";
echo "<br>";
}
//5.用mysql_result获得数据,并输出
for($rows_count=0;$rows_count<1;$rows_count++)
{
echo "5:书名:".mysql_result($result,$rows_count,"name")."<br>"; //这里warning
echo "5:价格:".mysql_result($result,$rows_count,"price")."<br>";//warning
echo "5:出版日期:".mysql_result($result,$rows_count,"publish_date");//warning
echo "<br>";
}
//6.mysql_fetch_array()获得数据,并输出
while($row=mysql_fetch_array($result)) //这里warning
{
echo "6:书名:".$row[1]."<br>";
echo "6:价格:".$row["price"]."<br>";
echo "6:出版日期:".$row["publish_date"]."<br>";
echo "<br>";
}
?>