Re: mysql_fetch_array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/3/07, Eduardo Vizcarra <evizcarra@xxxxxxxx> wrote:
>
> Hi guys
>
> After doing some changes, I believe it is partially working, what I did is
> the following:
>   while($row=mysql_fetch_array($fotos))
>   {
>    $fotos_mostrar[] = $row;
>   }
>   $primer_foto = reset($fotos_mostrar[0]); // This is to set the pointer
> to
> the first record
> echo $primer_foto; // This displays the first column when doing a SELECT
>
> However, my SELECT statement retrieves 2 columns from one table, how do I
> display the second column ?
>
> Thanks
> Eduardo



Since you're pulling 2 columns, why don't you use MYSQL_ASSOC option?
Example...

[code]
$query = "SELECT column1, column2 FROM table WHERE (...)";
...
while ($row = mysql_fetch_array ($fotos, MYSQL_ASSOC)) {
    $fotos_mostrar['col1'][] = $row['column1'];
    $fotos_mostrar['col2'][] = $row['column2'];
}
...
// To view the contents of what you just created
echo "<pre>";
print_r ($fotos_mostrar);
echo "</pre>";
[/code]

By doing it this way, you know exactly what you're storing and where.
Hopefully I didn't muddy things up! ;-)

~Philip

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux