mysql_fetch_array
不起作用。一切看起来都很好。我不知道我哪里做错了什么。
$sql = "SELECT * FROM `$tbl_name` limit $start,$limit";//if echo gives o/p Resource id #14
$resultw = mysql_query($sql);
while($gup=mysql_fetch_array($resultw))//if echo gives o/p Array
{
//if echo $gup['to']; gives o/p vicky.0989hyd@gmail.com;
$anusha=mysql_query("select * from users where email='$gup[to]'");//if echo gives o/p Resource id #15
while($resulter = mysql_fetch_array('$anusha'))//here is what iam getting error Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in
{
}
}
有人可以帮助我找出mysql_fetch_array
中的错误吗?
您可以使用以下命令检查查询中是否存在任何错误: mysql_error();
此函数返回 mysql 相关函数中最后一个生成的错误。只需使用以下语法:
$resultw = mysql_query($sql) or die(mysql_error());
$gup=mysql_fetch_array($resultw) or die(mysql_error());
while($gup)//if echo gives o/p Array
{
$email=$gup['to'];
$anusha=mysql_query("select * from users where email='$email'") or die(mysql_error());
//check $anusha here before pass it to mysql_fetch_array function
...
}
试试这个方式...我认为你在弄乱单引号和双引号
$sql = "SELECT * FROM `$tbl_name` limit $start,$limit";
$resultw = mysql_query($sql);
if (!$resultw) {
die('Invalid query: ' . mysql_error());
}
while($gup=mysql_fetch_array($resultw))//if echo gives o/p Array
{
$email=$gup['to'];
$anusha=mysql_query("select * from users where email='$email'");
if (!$anusha) {
die('Invalid query: ' . mysql_error());
}
//check $anusha here before pass it to mysql_fetch_array function
while($resulter = mysql_fetch_array($anusha))
{
//do what you want to do man
}
}
您应该尝试非常仔细地理解以下代码。这目前正在我的社交网站上使用,我希望这可以解决您的问题。
$st= "SELECT* FROM users WHERE username='$you'";
$result=mysqli_query ($con,$st);
$count=mysqli_num_rows ($result);
if($count==0){echo "<b>Profile not found! </b> ";}
else {echo "<b>Your Profile..</b>";}
while($row= mysqli_fetch_array ($result)) { echo "Username-<b>". $row ['uname']. "</b>"; echo "sent you this message";
echo "<p id='sms'>". $row ['sms']. "</p>";