Function, array - problem (probably easy to solve)
| From: | Tobias Talltorp | Date: | Wed, 14 Mar 2001 15:37:56 +0000 |
| Subject: | Function, array - problem (probably easy to solve) | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-43856@lists.php.net to get a copy of this message | ||
I am constructing a function for retrieving records from a mysql database
and putting them into an array called $print_field[name][number].
My problem is that I only seem to get the first two records and I think I
know where the problem is, but I can´t seem to be able to solve it.
Any ideas anyone?
<?
function print_query_array($query, $fields) {
global $print_field;
global $linkid;
// Determine what fields are selected
$field = explode("|",$fields);
$mysql_res = mysql_query($query,$linkid);
while ($strow = mysql_fetch_array($mysql_res))
$print_field[$field[0]][] = $strow[$field[0]]; // Problem
$print_field[$field[1]][] = $strow[$field[1]]; // Problem
}
}
print_query_array("SELECT field1, field2 FROM table LIMIT 10",
"field1|field2");
for ($i=0; $i<sizeof($print_field); $i++)
echo $print_field["field1"][$i]."<br>";
echo $print_field["field2"][$i]."<br>";
}
?>
Thanks,
// Tobias