Making 2-dimensional arrays...slight problem [Solved]
Posted: Wed Mar 21, 2007 5:16 pm
Gidday gang,
I'm trying to create a class that figures out how many columns a mysql query has, then makes an array with that number of columns. I'm new to PHP, but I imagine this is a fairly standard procedure. I've managed to make the array without any problems, but I'm having trouble returning the results.
Here's the difficulty:
The problem I have is that I can't figure out how to calculate (thenumberofrows) for the FOR loop. I'm guessing it's some sort of 'count' function, but the only count functions I know only return the number of columns, not rows. Here's the code I used to assemble the array in the first place:
If anyone has any suggestions, I'd be most appreciative. Apologies for the noob-ness of it all. :-p
Lotsa thanks,
- SG
I'm trying to create a class that figures out how many columns a mysql query has, then makes an array with that number of columns. I'm new to PHP, but I imagine this is a fairly standard procedure. I've managed to make the array without any problems, but I'm having trouble returning the results.
Here's the difficulty:
Code: Select all
function returnarray($array) {
$returnarray = '';
for ($i=0; $i<(thenumberofrows); $i++) {
foreach ($array as $key=>$value) {
$returnarray .= $value[$i];
}
}
}Code: Select all
function makearray($query) {
$connect = mysql_query($query, $this->connection);
if (!$connect)
{
die('Could not run the query');
}
else
{
$i = 0;
while($row = mysql_fetch_assoc($connect)) {
foreach ($row as $key=>$value) {
$returnthis[$key][$i] = $value;
}
$i++;
}
}
return $returnthis;
}Lotsa thanks,
- SG