canabatz Posted December 22, 2009 Share Posted December 22, 2009 $dacode="select * from `user_register` where username='user1' and password='user1'"; $result=mysql_query($dacode) or die('Error, query failed'); while ($row=mysql_fetch_assoc($result)) { if( $row['city'] == $_POST['city']) { echo "found it"; } else { echo "didnt find it": } } user1 have few citys in is list ,so when im sending a form to check if one of the citys are in the list it's just checking first row ,like the loop is not working! what im dong wrong? thanx Link to comment https://forums.phpfreaks.com/topic/186022-while-loop-problem/ Share on other sites More sharing options...
Buddski Posted December 22, 2009 Share Posted December 22, 2009 Have you echoed the number of results you are getting from the query.. it may not be what you expect. Link to comment https://forums.phpfreaks.com/topic/186022-while-loop-problem/#findComment-982321 Share on other sites More sharing options...
aeroswat Posted December 22, 2009 Share Posted December 22, 2009 Can we see your table? This is a problem in what the query is retrieving not your code. Link to comment https://forums.phpfreaks.com/topic/186022-while-loop-problem/#findComment-982322 Share on other sites More sharing options...
canabatz Posted December 22, 2009 Author Share Posted December 22, 2009 i have this as example for table usename password city user1 user1 city1 user1 user1 city2 user1 user1 city3 user1 user1 city4 user1 user1 city5 user1 user1 city6 user1 user1 city7 user1 user1 city8 i want in my code to check if city6 for example is allready in the list! thanx Link to comment https://forums.phpfreaks.com/topic/186022-while-loop-problem/#findComment-982323 Share on other sites More sharing options...
Buddski Posted December 22, 2009 Share Posted December 22, 2009 $dacode="select * from `user_register` where username='user1' and password='user1'"; $result=mysql_query($dacode) or die('Error, query failed'); if (mysql_num_rows($result) > 0) { while ($row=mysql_fetch_assoc($result)){ if ($_POST['city'] == $row['city']) { echo 'FOUND IT'; } } } else { echo 'no rows found matching your query'; } If running this code returns 'no rows found matching your query' it means your query isnt returning any results.. and you need to look at your query a little closer.. Also try: echo mysql_num_rows($result); Link to comment https://forums.phpfreaks.com/topic/186022-while-loop-problem/#findComment-982324 Share on other sites More sharing options...
canabatz Posted December 22, 2009 Author Share Posted December 22, 2009 thanx man ,that did da trick!!! Link to comment https://forums.phpfreaks.com/topic/186022-while-loop-problem/#findComment-982331 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.