papaface Posted April 15, 2007 Share Posted April 15, 2007 Hello, Can someone tell me how I can do this. I want to get the location from the database which i can do: $getbanners = mysql_query("select location from banners where frequency='{$basis}'"); list($location) = mysql_fetch_array($getbanners); There may be more than one record, therefore how can I put all the locations from the db into one array? Thanks Link to comment https://forums.phpfreaks.com/topic/47053-solved-get-from-db-and-put-into-an-array/ Share on other sites More sharing options...
MadTechie Posted April 15, 2007 Share Posted April 15, 2007 your need to use a loop to add to an array Link to comment https://forums.phpfreaks.com/topic/47053-solved-get-from-db-and-put-into-an-array/#findComment-229485 Share on other sites More sharing options...
papaface Posted April 15, 2007 Author Share Posted April 15, 2007 How do I do that? Link to comment https://forums.phpfreaks.com/topic/47053-solved-get-from-db-and-put-into-an-array/#findComment-229487 Share on other sites More sharing options...
MadTechie Posted April 15, 2007 Share Posted April 15, 2007 just a basic loop <?php $MyArray = array(); for($n = 0; $n < $rows; $n++) { $mysql_fetch_assoc($n); $MyArray[] = rows['TheData']; } ?> *untested Link to comment https://forums.phpfreaks.com/topic/47053-solved-get-from-db-and-put-into-an-array/#findComment-229501 Share on other sites More sharing options...
papaface Posted April 15, 2007 Author Share Posted April 15, 2007 Yeah, well considering I asked for help could you explain how to implement that into my setup. Otherwise that doesnt really help me. edit: You changed it. <?php $MyArray = array(); for($n = 0; $n < $rows; $n++) { $mysql_fetch_assoc($n); $MyArray[] = rows['TheData']; } ?> But what you posted wont work. Link to comment https://forums.phpfreaks.com/topic/47053-solved-get-from-db-and-put-into-an-array/#findComment-229503 Share on other sites More sharing options...
papaface Posted April 15, 2007 Author Share Posted April 15, 2007 I have put: $getbanners = mysql_query("select location from banners where frequency='d'"); $rows = mysql_fetch_assoc($getbanners); echo $rows['location']; But that only returns one location, when it should return 4. Why? Link to comment https://forums.phpfreaks.com/topic/47053-solved-get-from-db-and-put-into-an-array/#findComment-229506 Share on other sites More sharing options...
MadTechie Posted April 15, 2007 Share Posted April 15, 2007 I am here to help not to write the whole thing for you, their are many sections if you don't know how to use MySql with PHP you could of just asked what i posted was an example (which i updated to as it included some OOP) anyways good luck and good day Link to comment https://forums.phpfreaks.com/topic/47053-solved-get-from-db-and-put-into-an-array/#findComment-229508 Share on other sites More sharing options...
papaface Posted April 15, 2007 Author Share Posted April 15, 2007 I have helped so much in this community I think I am aware of that as I have said the same to others. However I am not asking for you to write a script I am asking for a very small piece of code! What you have provided does not help me. Link to comment https://forums.phpfreaks.com/topic/47053-solved-get-from-db-and-put-into-an-array/#findComment-229509 Share on other sites More sharing options...
papaface Posted April 15, 2007 Author Share Posted April 15, 2007 I have worked it out. Link to comment https://forums.phpfreaks.com/topic/47053-solved-get-from-db-and-put-into-an-array/#findComment-229514 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.