Posted by Ian Rutgers on 10/10/84 11:33
"Scott Johnson" <scottyj1@cox.net> wrote in message
news:ksZif.5278$pF.4266@fed1read04...
> Ian Rutgers wrote:
>> In querying a database
>>
>> ($result=query_db("SELECT photo_dir, photo_name FROM photograph_photo
>> WHERE photo_dir = '$dirToCheck'");
>>
>> is $result an array (where I could used a "in_array() function)?
>>
>> Thanks,
>>
>> Ian
> No the result is basicly a pointer to an external resource.
>
> You need to use an additional function to put that external resource into
> a usable value.
>
> The best way I find is to use (depending on the DB your using, there are
> different usages for each DB supported) is mysql_fetch_array($result)
>
> But with this you will need to step through the $result if more then one
> row is found.
>
> while($row = mysql_fetch_array($result)){
> foreach($row as $key => $vlaue){
> echo "Key: ".$key." (Value: ".$value.")";
> }
> }
>
> Hope this helps. If not post back.
> Scott
I thought I had this problem licked until I found I wasn't getting all the
values stored in my array ....
If I use:
while($row = mysql_fetch_array($result))
{
printf ($row["photo_name"]);
foreach($row as $key => $value)
{
$my_array[$key] = $value;
}
} //array now full of results from previous query
print_r($my_array);
$numArrayItems = count($my_array);
print("{$numArrayItems}\r");
I discover the numer of array items is only 2 (versus the 12 it should be).
If I use:
foreach($row as $value)
{
$my_array[] = $value;
}
I discover the number of array items is 24(double the number it should be).
What am doing wrong????
Thanks
[Back to original message]
|