drnrxv9383 2012-08-18 01:46
浏览 100
已采纳

mysql_query返回一行,但mysql_fetch_array没有做任何事情

I have a strange problem this time. I've got a masking database setup that takes in a url and gives it a string mask so that I can redirect users to another site (direct download) by giving them a link to my site's redirection engine.

I'm having a problem in the administrator side (where I put in the urls) where my mysql_fetch_array command just doesn't run. I know the query is returning at least one row because when I run the following code:

$query = "SELECT * FROM `urls` WHERE `in`='$lks[$i]' ORDER BY `id` DESC LIMIT 1";

$r = mysql_query($query);

if(mysql_num_rows($r) < 1)
echo "Less than 1";
else
echo "At least 1";

it returns "At least 1", but when it gets down to the mysql_fetch_array while statement, nothing happens. It's like it just ignores it completely.

CODE:

$query = "SELECT * FROM `urls` WHERE `in`='$lks[$i]' ORDER BY `id` DESC LIMIT 1";

$r = mysql_query($query);

while($me = mysql_fetch_array($r))
{
    echo "Blah";
}

Nothing is echoed by this code. What's wrong?

By the way, I know that I am connected to the database and everything because I run other commands very similar to this before this one and they all execute without any problems.

Also this command is in a for loop (I don't know why this would be a problem because I have done this many times before and never had any problems).

  • 写回答

3条回答 默认 最新

  • doujianjian2060 2012-08-18 01:51
    关注

    try echoing mysql_error(); I'm thinking it might be that you put your column and table names in quotes.

    $query = "SELECT * FROM urls WHERE in='$lks[$i]' ORDER BY id DESC LIMIT 1";
    $r = mysql_query($query);
    if($r)
    {
    $rowCount = mysql_num_rows($r);
    if($rowCount == 1)
    {
    echo "1 row";
    }
    }
    else
    {
    echo mysql_error(); 
    }
    

    if this doesn't work there must be something wrong with your array. :/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 采用的你的方案
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥15 对于这个问题的解释说明
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败