开发者

MYSQL & PHP: mysql ignoring first row [closed]

开发者 https://www.devze.com 2023-01-17 15:52 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 9 years ago.

I have never had this happen before. The query is very simple by the way.

$q  = mysql开发者_JAVA百科_query("SELECT * FROM $TABLE");  
while($r = mysql_fetch_array($q)) {  
    echo $r['fieldname'];  
}

edit: the first column (row) is skipped. but when I deleted the first column, the second one was ignored.

(SOLVED)

I figured it out. I declared mysql_fetch_array twice.

$q  = mysql_query("SELECT * FROM $TABLE");    
$r = mysql_fetch_array($q) //over here 


while($r = mysql_fetch_array($q)) {  
        echo $r['fieldname'];  
}

I have to be more careful, but thank you very much!


You should always use full list of columns in your select statement. Code you have posted is an example of bad programming. Do it this way

$q  = mysql_query("SELECT fieldname FROM $TABLE");  
while($r = mysql_fetch_array($q)) {  
    echo $r['fieldname'];  
}


Every thing seems okey, but it worth trying with MYSQL_ASSOC

$q  = mysql_query("SELECT * FROM $TABLE");  
while($r = mysql_fetch_array($q,MYSQL_ASSOC)) {  
    echo $r['fieldname'];  
}
0

精彩评论

暂无评论...
验证码 换一张
取 消