Jump to content

while loop problem


canabatz

Recommended Posts

$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
Share on other sites

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
Share on other sites

$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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.