Jump to content

funny coding error


thedevilinu

Recommended Posts

The actual code inside your while(){} loop is likely reusing and overwriting the $result variable, so when the while(){} loop is evaluated on the second pass through the loop, $result is no longer a result resource from the first query.

Link to comment
https://forums.phpfreaks.com/topic/222612-funny-coding-error/#findComment-1151242
Share on other sites

@PFMaBiSmAd -

I really expect the loop to run just once as their is only a single id associated with any email.

You are however right in saying that loop is running more than once. I can't fathom why it is running twice.

so changing the code to

------------------------------

$result = mysql_query("SELECT * FROM indiatutors_profiles WHERE id='$id' ") or die(mysql_error());

  while($row=mysql_fetch_array($result)){

      echo $email =$row;

  }

------------------

gives me error

----------------

[email protected]

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in website_path/profiles.php on line 7

----------

which confirms that loop runs twice. Bug was using another $result statement in the code due to which it was running again. Thanks for sorting this out for me.

Thanks again

 

@rifts - it works either way mate..my way is just time saving

@dragon - echo in or out of the loop .. either way it shouldn't give an error

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/222612-funny-coding-error/#findComment-1151441
Share on other sites

$query = "SELECT * FROM indiatutors_profiles WHERE id=$id"; // Presumes that $id is a numeric value.
$result = mysql_query($query) or die("<br>Query string: $query<br>Produced error: " . mysql_error());
$row=mysql_fetch_assoc($result);
echo $row['email']; // And yes, the array index should be enclosed in quotes. Just because it works without them, doesn't mean it's right.

Link to comment
https://forums.phpfreaks.com/topic/222612-funny-coding-error/#findComment-1151446
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.