...

View Full Version : Help needed setting comma seperated values as variables



btc_uk
01-08-2007, 04:46 PM
Hi,

I am trying to load numbers from a list in a MySQL database (I have no problem doing that) then I need to seperate them all out and have a variable for each.

For example, I have 6 comma seperated values stored in a datbase (1,2,3,4,5,6 for example) I then need to set a variable for each e.g. $n1 is set to 1, $n2 is set to 2, $n3 is set to 3, and so on (obviously these won't be the actual numbers, otherwise I could have just hard-coded them) and then I will be using these values in the rest of the script.

I can not change it so that the values from the database are provided any other way - they are always in this format.

Say the list in my database looks like this... 1,2,4,8,16,32

I would want variables like this:
$1 = 1
$2 = 2
$3 = 4
$4 = 8
$5 = 16
$6 = 32

Any help you can provide is much appreciated.
Ben

whizard
01-08-2007, 04:49 PM
Try this:


$data_chunks = explode(",",$list_from_database);


$data_chunks[0] = 1
$data_chunks[1] = 2
$data_chunks[2] = 4
$data_chunks[3] = 8
$data_chunks[4] = 16
$data_chunks[5] = 32

Regards,
Dan

btc_uk
01-08-2007, 04:58 PM
Many Thanks!

As always, i'm overcomplicating things!

All it needed was:


$banl = explode(",",$bans);

$t1 = $banl[0];
$t2 = $banl[1];
$t3 = $banl[2];
$t4 = $banl[3];
$t5 = $banl[4];
$t6 = $banl[5];

Cheers,
Ben


Try this:


$data_chunks = explode(",",$list_from_database);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum