Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-08-2007, 04:46 PM   PM User | #1
btc_uk
New to the CF scene

 
Join Date: Jan 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
btc_uk is an unknown quantity at this point
Help needed setting comma seperated values as variables

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
btc_uk is offline   Reply With Quote
Old 01-08-2007, 04:49 PM   PM User | #2
whizard
Senior Coder

 
whizard's Avatar
 
Join Date: Jan 2005
Location: Philadelphia, PA, USA
Posts: 1,457
Thanks: 10
Thanked 37 Times in 37 Posts
whizard will become famous soon enoughwhizard will become famous soon enough
Try this:
PHP Code:
$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
__________________
If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.
Step 1: Learn. Step 2: Search. Step 3: Post here.
whizard is offline   Reply With Quote
Old 01-08-2007, 04:58 PM   PM User | #3
btc_uk
New to the CF scene

 
Join Date: Jan 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
btc_uk is an unknown quantity at this point
Many Thanks!

As always, i'm overcomplicating things!

All it needed was:

PHP Code:
$banl explode(",",$bans);

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

Quote:
Originally Posted by whizard View Post
Try this:
PHP Code:
$data_chunks explode(",",$list_from_database); 
btc_uk is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:16 PM.


Advertisement
Log in to turn off these ads.