Home  >  Article  >  Backend Development  >  这么的嵌套查询,为什么查不到数据

这么的嵌套查询,为什么查不到数据

WBOY
WBOYOriginal
2016-06-13 10:34:46928browse

这样的嵌套查询,为什么查不到数据
数据表“Product”的结构和数据:



PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->include_once('conn.php');$result = mysql_query("SELECT p_class FROM Product group by p_class limit 40");//第一查询,已经能成功获得数据 mysql_data_seek($result, 0);    while ($row=mysql_fetch_row($result))    {      for ($i=0; $i<mysql_num_fields echo mysql_query from product where p_class="$tmp" limit while mysql_free_result></mysql_num_fields>


以上代码,循环次数已经正确,第一查询也是正确的,就是第二查询没数据。

------解决方案--------------------
你在while 里 $row=然后又 $row= ....第2个 $row 修改成 $row2=后面的保持一致,先这么改吧,我还没仔细看你代码。
------解决方案--------------------
这个跟你刚的问题是一样的
mysql_fetch_row
需要修改成 mysql_fetch_assoc()

一般 我们都返回关联数组
------解决方案--------------------
你这个使用的是
关联数组
echo $row['pic']; //这里查不到数据
echo $row['p_class']; //同上
echo $row['p_name']; //同上

所以你得返回关联数组 才能对上号嘛。。。如果你不是很明白可以将返回结果print_r 看看结构就知道了。

一般返回的都是关联数组,这样比较容易写代码.倒不是说只推荐,这个要看实际情况,大多数时候我们都是使用关联数组要多些.当然你也可以使用mysql_fetch_array这样返回了两种格式....
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn