Jump to content

Trying to get data from Array


Dave M

Recommended Posts

Hi all,

 

I'm trying to put a recordset into an array and retrieve data from the array.

 

The code I have used to create the array is:

 

$newarray = array(); 
$query = 'SELECT filename FROM phototable' . $where; 
$rs = mysql_query($query, $con) or die(mysql_error());

while($row=mysql_fetch_assoc($rs)) {array_push($newarray, $row);} 

 

When I use

<?php var_dump($newarray); ?>

this is returned:

 

array(4) { [0]=> array(1) { ["filename"]=> string(2) "29" } [1]=> array(1) { ["filename"]=> string(8) "13683-24" } [2]=> array(1) { ["filename"]=> string(2) "34" } [3]=> array(1) { ["filename"]=> string(2) "33" } }

 

I was hoping to use $newarray[0] to return the first value, $newarray[1] to return the second value etc, but when I type this i just get "array" as the result.....

 

How can I create an array that just returns values that I can access in the above method?

 

I am using MySQL 5.1.37

My table is called phototable the column I want to create the array from is called filename

 

Many thanks in advance,

 

Dave.

 

 

Link to comment
https://forums.phpfreaks.com/topic/184506-trying-to-get-data-from-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.