Re: Why is this code not working?
| From: | CPT John W. Holmes | Date: | Wed, 12 Nov 2003 19:04:54 +0000 |
| Subject: | Re: Why is this code not working? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-169344@lists.php.net to get a copy of this message | ||
From: "Dave G" <ml@autotelic.com>
> PHP Gurus,
If you say so...
> I'm trying to put the results of a query into an array.
> My code looks like this:
> <?php
> $query = "SELECT datecolumn FROM table WHERE MONTH(datecolumn) = " .
> $currentMonth;
> $result = mysql_query($query);
> $numRows = mysql_num_rows($result);
> for($i = 0; $i<$numRows; $i++)
> {
> $workshops[$i] = mysql_fetch_row($result);
> echo $workshops[$i] . "<br />";
> }
> echo "The results of the array are - " . $workshops[0] . " and " .
> $workshops[1];
> ?>
> When I run this, the output to the screen says:
> ---
> Array
> Array
> The results of the array are - Array and Array
> ---
Exactly what it should be. mysql_fetch_row returns an array, which you're
assiging to $workshops[0] and $workshops[1].
Try:
echo "The results of the array are - " . $workshops[0][0] . " and " .
$workshops[1][0];
Or, even better...
$query = "SELECT datecolumn FROM table WHERE MONTH(datecolumn) = " .
$currentMonth;
$result = mysql_query($query);
while($r = mysql_fetch_row($result))
{ $workshop[] = $r[0]; }
echo "The results of the array are - " . $workshops[0] . " and " .
$workshops[1];
---John Holmes...