Re: mysql_query
| From: | Alexander Deruwe | Date: | Sun, 14 Oct 2001 20:21:55 +0000 |
| Subject: | Re: mysql_query | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-71040@lists.php.net to get a copy of this message | ||
On Sunday 14 October 2001 17:22, Peter wrote:
> $sql_result_count1 = mysql_query($sql_count1, $connection) or die
> ("Couldn't get count!");
>
> $count1 = mysql_result($sql_result_count1,0,"count(modelno)");
>
> Why do I need a "0" and the "count(modelno)" function again at the very
> end?
The 0 means: Get the first record in the resultset $sql_result_count1
"count(modelno)" is the name of the field you're going to pull from the
resultset. For example if you had said: "SELECT field_x FROM table WHERE key
= 1" then you would have to write mysql_result($resultset, 0, "field_x");
As for the 0, you will quickly understand when you see the next example:
$query = "SELECT field_x FROM table";
.. get the query into the $resultset variable ..
// put all the results into an array
$Index = 0;
$FieldArray = array();
while ($Field = mysql_result($resultset, $Index, "field_x"))
{
array_push($FieldArray, $Field);
$Index++;
}
(NOTE: I did not test this snippet)
You see that you have to increment the value of $Index starting from 0 to get
all the records sequentially.
Hope that helped,
Alexander