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条)

报告相同问题?