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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Location
    Uppsala, Sweden
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Variable array with data from MySQL

    Hi!

    I'm an hobby-programmer in PHP and MySQL that has run into a problem.
    I've been reading about variable variables in PHP, but can't get it to work for the specific case I need it to. Here's the set-up:

    I have a table named participants. The participants have one line each, but are mostly paired up in couples. This is done by a column named id - so two lines have the same value (1, 2, 3...) in the id-column.
    I then query the database (aocuserlogin is a cookie set by a simple loginscript)
    $qloadarray = mysql_query("SELECT * FROM participants WHERE (id='$aocuserlogin')");
    while ($rloadarray = mysql_fetch_array($qloadarray, MYSQL_ASSOC)) {
    $loadedarray = array($rloadarray[firstcolumn],$rloadarray[secondcolumn],$rloadarray[thirdcolumn]);
    }

    Since the while-loop is going to run twice I want to set the variable for the array to a name from the specific row that is running.
    I mean I want the variable to be named as the value in the fourth column of the active row - does that make sense?

    I have been trying something like
    $$rloadarray[fourthcolumn] = array(...
    but this doesn't work.
    I've also tried
    ${$rloadarray[fourthcolumn]} = array(...
    Which doesn't work either...

    Does someone have an idea?

    Please ask if you need additional information - it's hard to explain...

    Thanks a million!!!

  • #2
    Regular Coder
    Join Date
    Nov 2009
    Location
    Hamilton, New Zealand
    Posts
    126
    Thanks
    0
    Thanked 17 Times in 17 Posts
    PHP Code:
    <?php
    $a
    [$rloadarray[fourthcolumn]] = array($rloadarray[firstcolumn],$rloadarray[secondcolumn],$rloadarray[thirdcolumn]);

    ?>
    Not exactly what you wanted, but easier to keep track of in my opinion.
    Affordable Web Design (New Zealand Based)
    Internet Marketing Guru
    PHP/mySQL Expert
    -------------------------------------------


  •  

    Posting Permissions

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