Jump to content

PHP Arrays


besly98

Recommended Posts

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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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/>";

?>

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.