Re: mysql_fetch_array

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

 



Eduardo Vizcarra 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


if you notice you are referring to an index in your array.

You should be doing the reset on $fotos_mostrar like this

reset($fotos_mostrar);

var_dump($fotos_mostrar);

This will display the entire dataset.

also, if you read the first line just above the first example of use, you will notice that it says that reset will return the first array element or false.

The reason that you are getting the first column is because in your reset call, you are referencing the first index entry in your array.

This would return you the first index of the first index in your array.

NO, I did not just repeat myself. re-read what I wrote and think it through and it will make perfect sense.

So, try what I showed you at the beginning of my comments and you will see the results you are wanting.

However, my SELECT statement retrieves 2 columns from one table, how do I display the second column ?

Thanks
Eduardo

"Jim Lucas" <lists@xxxxxxxxx> escribió en el mensaje news:472D0EDA.4030709@xxxxxxxxxxxx
Eduardo Vizcarra wrote:
I have a WHILE sentence to retrieve all records from a SELECT query in a database and am using mysql_fetch_array to store them in a matrix, the sentence is like this:
  while($row=mysql_fetch_array($fotos))
  {
   $fotos_mostrar[] = $row;
  }

$fotos contains all records found in a db table, the SELECT statement is retrieving 2 columns from a table, how do I store all records in a 2 dimention table so I can use it later ?

this WHILE sentence seems to only store the last record only

Regards
how are you checking to see the contents of the $fotos_mostrar array() ?

just after the while loop ends, do a var_dump() or print_r() on the array and view the contents.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[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