besly98 Posted April 28, 2011 Share Posted April 28, 2011 hi all, how can i make this array dynamic. E.g, i want the numbers to be pulled from a database... $s=array( "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" ); thanks in advance, i just cant work it out Quote Link to comment https://forums.phpfreaks.com/topic/234963-php-arrays/ Share on other sites More sharing options...
cssfreakie Posted April 28, 2011 Share Posted April 28, 2011 you might want to have a read on the database handling tutorial on this site: http://www.phpfreaks.com/tutorials when you connect to a database an fetch the result, the result is given in the form of an array. So in other words, ones you created a table in a database where you store numbers you can fetch them in the form of an array. And by using insert or update you can increase or edit the numbers of rows stored in that database. HAve a look it's fun. If you never ran a database have a look into WAMP (windows) or MAMP if your a a mac user. Quote Link to comment https://forums.phpfreaks.com/topic/234963-php-arrays/#findComment-1207489 Share on other sites More sharing options...
besly98 Posted April 28, 2011 Author Share Posted April 28, 2011 oh sorry, i stil dont understand really. this is my full code, what im trying to do is substitute the array at the top for a dynamic array from a table. can you help? $s=array( "1", "2", "3", ); $nums=sizeof($s); $days=array(); $_list=array_keys($s); $tmp_list=array_splice($_list,1,sizeof($_list)-1); $count=sizeof($tmp_list)+1; $days=array(); for($i=0;$i<$nums-1;$i++){ $days[$i]=array(); $day_list=array_merge(array($_list[0]),$tmp_list); for($j=0;$j<$count/2;$j++){ echo $s[$day_list[$j]].'V'.$s[$day_list[$count-$j-1]]."<br/>"; } //rotate$tmp_list $elm=array_shift($tmp_list); array_push($tmp_list,$elm); } print_r($days)."<br/>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/234963-php-arrays/#findComment-1207502 Share on other sites More sharing options...
cssfreakie Posted April 28, 2011 Share Posted April 28, 2011 I have no idea what you mean. Can you maybe tells us in a more precise/descriptive manner what you want to achieve (so what do you want the outcome to look like). Quote Link to comment https://forums.phpfreaks.com/topic/234963-php-arrays/#findComment-1207507 Share on other sites More sharing options...
besly98 Posted April 28, 2011 Author Share Posted April 28, 2011 well, instead of the following array, $s=array( "1", "2", "3", ); i want the array 1, 2, 3 to be populated by a id which is pulled out of my database. Quote Link to comment https://forums.phpfreaks.com/topic/234963-php-arrays/#findComment-1207511 Share on other sites More sharing options...
cssfreakie Posted April 28, 2011 Share Posted April 28, 2011 okay, so the first response i gave, have a look at the database handling tutorial is what you need. It learns you how to fetch stuff from your database and put it in the form of an array. If that is not the case i have no idea. incase you found the previous link complicated: http://www.phpfreaks.com/tutorials here is a direct one: http://www.phpfreaks.com/tutorial/php-basic-database-handling Quote Link to comment https://forums.phpfreaks.com/topic/234963-php-arrays/#findComment-1207514 Share on other sites More sharing options...
Muddy_Funster Posted April 28, 2011 Share Posted April 28, 2011 you will need to connect to the server, select your database and then select your information from your table that you want to use. once you have done that you will be able to manipulate it in PHP. You will need to read through the tutorial. Quote Link to comment https://forums.phpfreaks.com/topic/234963-php-arrays/#findComment-1207515 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.