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