日期:2014-05-17 浏览次数:20570 次
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($result); $i++ ) { $tmp=$row[$i]; //把查询结果赋值为新变量:$tmp echo $tmp;//这里已经可以在web段显示正确的字段内容 $result2 = mysql_query("SELECT * FROM Product where p_class=$tmp limit 0,4");//开始嵌套查询 while ($row=mysql_fetch_row($result2)) { echo $row['pic']; //这里查不到数据 echo $row['p_class']; //同上 echo $row['p_name']; //同上 } } } mysql_free_result($result); mysql_free_result($result2); mysql_close($conn);