PHP while() fails to stop looping -


i getting problem because using while() function i'm solving 5 or 6 hours today. i'm asking here because don't understand how be. here code

$sql = mysql_query("select saldo stock id >= '$id' , iditem = '$iditem';") 

if try :

$row = mysql_fetch_array($sql); while($row) {   // code here } 

then, while() fails stop looping. if try this:

while($row = mysql_fetch_array($sql)) {//my code here  } 

by code, i'm getting correct result.

i feel little strength because think first , second code have same function. comments or answers!

mysql_fetch_array() fetches 1 row @ once when use in while fetch next row every time. returns true if there next row fetch , false if there not.

for preventing infinite loop, use correct syntax fetching:

while($row = mysql_fetch_array($sql)) {        //your code } 

note: original mysql extension deprecated, , generate e_deprecated errors when connecting database. instead, use mysqli or pdo_mysql extensions


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

qt - How to embed QML toolbar and menubar into QMainWindow -