Reputation: 2445
I have a question about PHP WHILE
loops. I know that you can perform the action mysql_num_rows to get the number of results from a SELECT
query.
But say I have 3 results come through the select query and i put them through a while loop, how do I assign a variable to the number each result is in the mysql_num_row
.
Such as
1 for result 1
2 for result 2
3 for result 3.
Sorry if this is a bit confusing, but i can't seem to find an easy way to explain it.
Thanks
Upvotes: 0
Views: 1142
Reputation: 1036
There are a few 'new' methods for pulling back data from MySQL now, if you're just starting out this might be the ideal time to have a look at them. This looks like a good place to start: http://www.php.net/manual/en/mysqlinfo.api.choosing.php.
Upvotes: 0
Reputation: 5905
You do it like this:
$results = array();
While ($row = mysql_fetch_assoc($result))
{
$results[] = $row;
}
Upvotes: 2
Reputation: 3333
$res=array();
$i=0;
While(mysql_fetch_array(...)){
$i++;
$res[$i]=value
//do logic
}
Upvotes: 0
Reputation: 4370
$myArray = array();
while($row = mysql_fetch_assoc($result)) {
$myArray[] = $row
}
Upvotes: 0