zgkhoo Posted October 8, 2007 Share Posted October 8, 2007 function detect(){ $counter=0; echo "</br>detect"; $result=mysql_query("SELECT * FROM result") or die('Query failed: ' . mysql_error()); while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { echo "</br>counter=$counter"; echo "</br>$row[Category]"; echo "</br>Drawdate in sql=$row[DrawDate]"; echo "</br>POST drawdate=$_POST[drawnumber]"; if ($row[Category]=='Magnum'&& $row[DrawDate]==$_POST[drawnumber]) { echo "if"; return 1; }//end if else{ echo "else"; return 0; } $counter++; }//end while }//end detect() it just will detect one first record of the mysql database. y? it just appear detect counter=0 SgPools Drawdate in sql=2007-07-09 POST drawdate=2007-08-08else0 after i remove the if else statement then it can successfully display all 5 record. anyone know y? Quote Link to comment https://forums.phpfreaks.com/topic/72323-solved-while-loop-problem/ Share on other sites More sharing options...
kenrbnsn Posted October 8, 2007 Share Posted October 8, 2007 You have a "return" statement in you're "if". This ends the loop. Please spell out all your words ... Ken Quote Link to comment https://forums.phpfreaks.com/topic/72323-solved-while-loop-problem/#findComment-364676 Share on other sites More sharing options...
zgkhoo Posted October 8, 2007 Author Share Posted October 8, 2007 "return" keyword end the loop? why not "break" end the loop? others programming language also like that? ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/72323-solved-while-loop-problem/#findComment-364680 Share on other sites More sharing options...
sasa Posted October 8, 2007 Share Posted October 8, 2007 "return" keyword end the function Quote Link to comment https://forums.phpfreaks.com/topic/72323-solved-while-loop-problem/#findComment-364682 Share on other sites More sharing options...
haaglin Posted October 8, 2007 Share Posted October 8, 2007 break; ends the current loop EDIT: Haha.. meant continue.. sorry.. Quote Link to comment https://forums.phpfreaks.com/topic/72323-solved-while-loop-problem/#findComment-364685 Share on other sites More sharing options...
kenrbnsn Posted October 8, 2007 Share Posted October 8, 2007 You want to use the continue statement. Ken Quote Link to comment https://forums.phpfreaks.com/topic/72323-solved-while-loop-problem/#findComment-364686 Share on other sites More sharing options...
zgkhoo Posted October 8, 2007 Author Share Posted October 8, 2007 return 0; return 1; end the function how abt return $found; ? Quote Link to comment https://forums.phpfreaks.com/topic/72323-solved-while-loop-problem/#findComment-364687 Share on other sites More sharing options...
MmmVomit Posted October 8, 2007 Share Posted October 8, 2007 Is this what you're trying to do? <?php function detect() { $counter=0; echo "</br>detect"; $result=mysql_query("SELECT * FROM result") or die('Query failed: ' . mysql_error()); while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { echo "</br>counter=$counter"; echo "</br>$row[Category]"; echo "</br>Drawdate in sql=$row[DrawDate]"; echo "</br>POST drawdate=$_POST[drawnumber]"; if ($row[Category]=='Magnum'&& $row[DrawDate]==$_POST[drawnumber]) { echo "if"; // return 1; }//end if else { echo "else"; continue; // return 0; } $counter++; }//end while return $counter; }//end detect() ?> Quote Link to comment https://forums.phpfreaks.com/topic/72323-solved-while-loop-problem/#findComment-364695 Share on other sites More sharing options...
zgkhoo Posted October 8, 2007 Author Share Posted October 8, 2007 function detect(){ $counter=0; $found=0; echo "</br>detect"; $result=mysql_query("SELECT * FROM result") or die('Query failed: ' . mysql_error()); while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { echo "</br>counter=$counter"; echo "</br>$row[Category]"; echo "</br>Drawdate in sql=$row[DrawDate]"; echo "</br>POST drawdate=$_POST[drawnumber]"; if ($row[Category]=='SgPools'&& $row[DrawDate]==$_POST[drawnumber]) { echo "if"; $found=1; }//end if else{ echo "else"; } $counter++; }//end while return $found; }//end detect() solved..thanks.. Quote Link to comment https://forums.phpfreaks.com/topic/72323-solved-while-loop-problem/#findComment-364699 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.