Jump to content

MySQL_fetch?


eduard
 Share

Recommended Posts

This: while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; }I don´t understand! (MySQL SELECT) (mysql_fetch?)

Link to comment
Share on other sites

mysql_query does not return data you can use directly. $result is not a string or an array or an object. It is a data type called a resource. Resources cannot be examined. They are only useful when you pass them to certain built-in PHP functions, like mysql_fetch_array.When you pass the result of mysql_query to mysql_fetch_array, it returns the first matching record as an array. The next time you call mysql_fetch_array, the second row is returned, and so on until there are no more rows. That is why mysql_fetch_array is normally used in a loop. The loop will terminate when mysql_fetch_array stops returning anything.

Link to comment
Share on other sites

mysql_query does not return data you can use directly. $result is not a string or an array or an object. It is a data type called a resource. Resources cannot be examined. They are only useful when you pass them to certain built-in PHP functions, like mysql_fetch_array.When you pass the result of mysql_query to mysql_fetch_array, it returns the first matching record as an array. The next time you call mysql_fetch_array, the second row is returned, and so on until there are no more rows. That is why mysql_fetch_array is normally used in a loop. The loop will terminate when mysql_fetch_array stops returning anything.
Could you give an example please?
Link to comment
Share on other sites

No. If you know that exactly one record will be returned by mysql_query, you may call mysql_fetch_array only once, not in a loop.Even if mysql_query returns more than one result, you might have a special reason for calling mysql_fetch_array several times, in different parts of your script, not in a loop. You might do that if the data for each recorded need to be output differently.

Link to comment
Share on other sites

Guest ongirlgames.com
No. If you know that exactly one record will be returned by mysql_query, you may call mysql_fetch_array only once, not in a loop.Even if mysql_query returns more than one result, you might have a special reason for calling mysql_fetch_array several times, in different parts of your script, not in a loop. You might do that if the data for each recorded need to be output differently.
if select a record: use: $rs=mysql_fetch_array($result);else muiltiple record: use: while($r=mysql_fetch_array($result)){ anything; } return $r;
Link to comment
Share on other sites

if select a record: use: $rs=mysql_fetch_array($result);else muiltiple record: use: while($r=mysql_fetch_array($result)){ anything; } return $r;
Thanks!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...