SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jan 2002
    Location
    los angeles
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation crazy variable concatenation problem

    Hey all...
    I have a wacky problem I hope you can help me solve.

    I have a variable being passed from a form called $button1name.
    I will have a few of these, in succession $button2name, $button3name, etc.

    The problem is that I have a while loop traversing through an array of SQL items and I am using $row[ID] to get which line I am at. No problems yet.

    the problem comes when I want to update the current row using $button$row[ID]name.

    I have tried :
    "$button".$row[ID]."name" // returns a string
    "\$button".$row[ID]."name" // returns a string
    $button.$row[ID]."name" //returns 1name

    i can't get any of that stuff to return tha actual value of $button1name...

    any clues?

    thanks for any help in advance.
    rob

  2. #2
    Action! filmfoto's Avatar
    Join Date
    Dec 2001
    Location
    Sweden
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It would be better if you named your form entries "buttonname[]". That way they will be posted as an array. Then all you have to do is loop through this array calling it like this:
    PHP Code:
    $buttonname[$row[ID]]; 



    Hope this helps.

    Cheers.

  3. #3
    SitePoint Member
    Join Date
    Jan 2002
    Location
    los angeles
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I have 4 text fields I am updating

    $button1name
    $button1link
    $button1image
    $button1rollover

    so that's why I did it this way.

    am I doing it wrong?

    if so, i can change how the variables are set up with a wee bit of work.

    thanks!

  4. #4
    SitePoint Member
    Join Date
    Jan 2002
    Location
    los angeles
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and my sql table looks like:
    +----+------+-----------+-------+----------+
    | ID | link | text_name | image | rollover |
    +----+------+-----------+-------+----------+


    so each row has all that data, and that's why i am doing it the way i stated.
    once again...if that's all not right then I can change how I am doing things...although changing the database table now would be a pain

  5. #5
    purple monkey dishwasher scoates's Avatar
    Join Date
    Nov 2001
    Location
    Montreal
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $button is empty. Thay's why you're getting "1name";

    for:
    $bn = $button1name

    $var = "button". $row[ID] ."name";
    $bn = $$var;

    OR

    $bn = ${"button'. $row[ID] ."name"};

    ---

    S

  6. #6
    SitePoint Member
    Join Date
    Jan 2002
    Location
    los angeles
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    thanks scoates...

    I never got a chance to say thanks (I had a car wreck that day you replied...annoying as hell!!) buti wanted to say thanks anyway.

    the $bn = ${"button'. $row[ID] ."name"};
    method didn't work for some reason but the other one did so that's fantabulous.

    thanks again!
    rob


Bookmarks

Posting Permissions

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