php查询数据库
<?php
session_start();
include("../../control/config.php");
$id=$_SESSION['user'];
$p_id=$_GET['id'];//试卷ID
$time=$_GET['t_time'];
$result=mysql_query("select * from PAPERS where P_ID='$p_id'");
$rows=mysql_fetch_assoc($result);
preg_match_all('/(\d{2}|\d{1}|\d{3}?)/',$rows['P_QUES'], $timu);//获取题目数组
for ($i=0;$i<count($timu[0]);$i++)
{
$question=$timu[0][i];
$result1=mysql_query("select * from QUESTION where Q_ID='$question'")
while($rows1=mysql_fetch_array($reslut1))
{
echo "题目:".$rows1['Q_TEXT'];
echo "选项A:".$rows1['Q_A'];
echo "选项B:".$rows1['Q_B'];
echo "选项C:".$rows1['Q_C'];
echo "选项D:".$rows1['Q_D'];
echo "<br/>";
}
}
mysql_close($db);
?>
提示红色返回不是有效结果集··错在哪?
[解决办法]
$result1=mysql_query("select * from QUESTION where Q_ID='$question'") 单引号去掉,加了单引号不会被解析。
[解决办法]
$reslut1查询出来的可能是空值,没有记录。你把sql在mysql中调试一下,看看有没有结果。