php查询功能教程,php的查询功能(如何通过查询条件获取相应表的字段)

\n"; echo "

isbn author title price "; echo "\n"; //循环遍历 while ($myrow = mysql_fetch_row($result)){ printf("

%s %s %s %s", $myrow[0], $myrow[1],$myrow[2],$myrow[3]); } echo "\n";?>无标题文档

回复讨论(解决方案)

请描述下你遇到的问题

result = mysql_query("select * from books where checked=‘$checked’ ");

比如输入要查询的isbn号,然后确定,在下方输出符合条件的查询结果。

result = mysql_query("select * from books where checked=‘$checked’ ");这个我试了一下,出现以下错误

还有一个问题要请教是如何是要先查询之后才显示表要显示的结果。

... where 字段='$checked' //字段换成你实际的字段

if(isset($_POST['checked'])){

@$result = mysql_query("select * from books",$db);

echo "\n";

echo "

isbn

author

title

price

";

echo "\n";

//循环遍历

while ($myrow = mysql_fetch_row($result)){

printf("

%s

%s

%s

%s", $myrow[0], $myrow[1],$myrow[2],$myrow[3]);

}

echo "\n";

}

谢谢jordan102,那请问如何通过查询条件,然后在同个页面下输出符合查询条件的表呢?

这是我的表

我试了jordan102的代码,也不知道我添加if(isset($_POST['checked'])){.......}这段代码的位置对不对。

我按了下查询的按钮,但是没反应。代码如下\n"; echo "

isbn author title price "; echo "\n"; //循环遍历 while ($myrow = mysql_fetch_row($result)){ printf("

%s %s %s %s", $myrow[0], $myrow[1],$myrow[2],$myrow[3]); } echo "\n";} ?>无标题文档

@$result = mysql_query("select * from books where isbn='$checked'",$db);

@jordan102我试了下@$result = mysql_query("select * from books where isbn='$checked'",$db); 但是点了按钮还是不行。

这句我试了,但是我输入books的isbn到输入框的时候,点击查询,还是查不到isbn=1的对应的全部内容。

只出来一部分数据,那你检查下没查出来的数据哪里不同。

$result = mysql_query("select * from books",$db);

条件都不加,还算是条件查询吗?

我运行之后没有数据表显示,显示结果如下:

会不会是那些字段没对应呢?

回复xuzuning,不好意思!忘了加。

没有符合条件的记录,自然列表就是空的

回复Jordan120,还是没有表显示。

回复xuzuning,请问这句不是@$result = mysql_query("select * from books where isbn='$checked'",$db);通过查询isbn的编号然后判断符合条件的来输出表。

表头也没有显示吗?

回复Jordan02:没有显示

现在的代码是如何写的,贴出来看看。

\n"; echo "

isbn author title price "; echo "\n"; //循环遍历 while ($myrow = mysql_fetch_row($result)){ printf("

%s %s %s %s", $myrow[0], $myrow[1],$myrow[2],$myrow[3]); } echo "\n";} ?>无标题文档

@$result = mysql_query("select * from books where isbn=' $checked'",$db);

在哪里赋值的???

嗦嘎,我在#18标红了你还抄错。\n";

echo "

isbn

author

title

price

";

echo "\n";

//循环遍历

while ($myrow = mysql_fetch_row($result)){

printf("

%s

%s

%s

%s", $myrow[0], $myrow[1],$myrow[2],$myrow[3]);

}

echo "\n";

}

?>

无标题文档

\n";

echo "

isbn

author

title

price

";

echo "\n";

//循环遍历

while ($myrow = mysql_fetch_row($result)){

printf("

%s

%s

%s

%s", $myrow[0], $myrow[1],$myrow[2],$myrow[3]);

}

echo "\n";

}

?>

无标题文档

回复qxhaidao、jordan102:折腾了两位一个下午,qxhaidao的代码运行成功,jordan那个只显示了表头。我会给两位加分的,实在谢谢了!

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值