Dave M Posted December 9, 2009 Share Posted December 9, 2009 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( "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. Quote Link to comment https://forums.phpfreaks.com/topic/184506-trying-to-get-data-from-array/ Share on other sites More sharing options...
sasa Posted December 9, 2009 Share Posted December 9, 2009 while($row=mysql_fetch_assoc($rs)) {array_push($newarray, $row['filename']);} Quote Link to comment https://forums.phpfreaks.com/topic/184506-trying-to-get-data-from-array/#findComment-974026 Share on other sites More sharing options...
Dave M Posted December 9, 2009 Author Share Posted December 9, 2009 Hi, Thanks for getting back to me so quickly. If I type <?php $newarray[0]; ?> nothing is returned. I would expect 29 to be returned. Given that that is the first value in the array. Thanks again, Dave. Quote Link to comment https://forums.phpfreaks.com/topic/184506-trying-to-get-data-from-array/#findComment-974034 Share on other sites More sharing options...
Dave M Posted December 9, 2009 Author Share Posted December 9, 2009 Yes yes, OK I know what I have done! try echo.... Again, thanks a million, Dave. Quote Link to comment https://forums.phpfreaks.com/topic/184506-trying-to-get-data-from-array/#findComment-974035 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.