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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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); Quote Link to comment Share on other sites More sharing options...
canabatz Posted December 22, 2009 Author Share Posted December 22, 2009 thanx man ,that did da trick!!! Quote Link to comment 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.