Fwd: Re: [PHP-DB] numeric string to single digit array
| From: | Richard Dunne | Date: | Wed, 26 Mar 2008 18:35:14 +0000 |
| Subject: | Fwd: Re: [PHP-DB] numeric string to single digit array | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-44816@lists.php.net to get a copy of this message | ||
Using this extract from http://ie.php.net/manual/en/control-structures.foreach.php
Amaroq
09-Mar-2008 06:40
Even if an array has only one value, it is still an array and foreach will run it.
<?php
$arr[] = "I'm an array.";
if(is_array($arr))
{
foreach($arr as $val)
{
echo $val;
}
}
?>
The above code outputs:
I'm an array.
-------------------------------------
So if I use:
$query = "Select answer from answers where studentID='A123456789'";
$result = mysql_query($query,$connection) or die(mysql_error());
while($row = mysql_fetch_assoc($result))
{
foreach($row as $answer)
{
echo $answer . "\n";
}
}
I thought I would be able to print out each array element, but I am not getting any output. Has
anyone got a better idea?