Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    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
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •