www.webdeveloper.com
Results 1 to 7 of 7

Thread: variables in variables?

  1. #1
    Join Date
    Dec 2002
    Location
    Canada, eh?
    Posts
    228

    variables in variables?

    alright, its me again with another question...

    im working on a loop that produces a row of table cells with info in them...all the info is stored in variables numbered 1 to 10, like this:

    $o1
    $o2
    $o3
    ...
    $o10

    now what i want to do is, inside that loop, cycle through the 10 different variables...but are variables inside variables allowed? heres the basic structure i have so far:

    PHP Code:
    for($i 1$i <= $n$i++){
     
     
    $contents .= "
        <tr>
         <td>
          <b>
    $o".$i.":</b>
         </td>
         <td class=\"bar\">
          <img alt=\"Bar\" src=\"bar.gif\" width=\"
    $res".$i."\" height=\"7\" /> - $res".$i."% - ".$sofar['opt$i']." votes\n";
         </
    td>
        </
    tr>";


    as you can see, $i is put in several times, including inside the key of an array...would this work? thanx in advance

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,123
    how about array inside of an array?
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  3. #3
    Join Date
    May 2003
    Posts
    550
    Yes they are. I didn't check if your script will work, but you can use variables with another variable.
    Example

    $o1 = 0;
    $o2 = $o1 + 1;

    Now the value of o2 is NOT $o1 + 1, the value of o2 is 1. When you point to a variable in another variable, the contents of the variable are actually copied, not just a pointer to the first variable.
    Just a guess, but the same is probably true for an array.

  4. #4
    Join Date
    Dec 2002
    Location
    Canada, eh?
    Posts
    228
    so brendan, youre saying that something like this:

    PHP Code:
    $contents "<b>$o".$i.":</b>"
    should work fine? so the first time through the loop, it should print out the value of $o1? alright then, ill try it out...otherwise ill try to work the code so $o is set to an array...it should work...

    oh, another question: to set the values of an array, do you have to use the array() function? or can values simply be set like:

    $o[1] = 8;
    $o[2] = 5;

    etc etc, without even touching the array() function?

  5. #5
    Join Date
    Dec 2002
    Location
    Canada, eh?
    Posts
    228
    well the variables in variables thing doesnt work, so i had to redo my entire section of code in order to implement arrays instead...then $o[$i] worked fine

    but i have ONE last question, and then i think ill be done this script and it can go into my free script database (check out my sig - CrossFade Studios)...

    alright, i have a checkbox:

    <input type="checkbox" name="clear" value="clearpoll" />

    now how do i access the value of $clear? i tried saying

    if($clear == "clearpoll"){

    but that doesnt seem to work...is there something im missing, or should i just do something like this?

    if($clear != null){

    edit: alright, using null works fine...thanx me
    Last edited by Da Warriah; 07-18-2003 at 02:51 PM.

  6. #6
    Join Date
    May 2003
    Posts
    550
    $_POST['clear']
    or
    $_GET['clear']

  7. #7
    Join Date
    Dec 2002
    Location
    Canada, eh?
    Posts
    228
    yeah i used $clear = $_POST["clear"]; just cause i find it easier to work with if i have to type it out a million times...the thing is that i wasnt sure what value it gave out when the checkbox was checked - for things like textboxes and such, the value is returned, but for a checkbox, both the name and value are already defined...anyways it works now, so problem is solved

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles