SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2000
    Location
    Cork, Ireland
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to be able to dynamically create variable names in a for loop.

    For example I have variables from $thing1, $thing2, $thing3 to $thing10.
    I want to be able access these variables in a for loop which goes from 1 to 10.

    Please help me?? If it's possible, I don't even know if it is...

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2000
    Location
    Cork, Ireland
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $thing1, $thing2 etc, are posted to PHP using a FORM. In case that helps.

    If it's not possible, any other solution???

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2000
    Location
    Cork, Ireland
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The variables come from a list of checkbox's from a table in a form, each checkbox represents a record which will be deleted if selected, a selected checkbox VALUE contains the ID of the record which is to be deleted.

    Hope this helps...

  4. #4
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The solution to this exact issue is given in Part 6 of my article series, "Building a Database-Driven Web Site using PHP and MySQL" on SitePoint.com. The exact page where this is discussed is here: Managing Jokes (cont'd.)

    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!

    [This message has been edited by kyank (edited July 04, 2000).]

  5. #5
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems to me like an array would be the best solution in this case. So for example $thing1 would be $things[0] and $thing10 would be $things[9].

    Hope this helps...

  6. #6
    SitePoint Enthusiast
    Join Date
    Jun 2000
    Location
    Cork, Ireland
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Kevin that worked very well,

    I've now put a delete all checkbox into the form. The only problem is that If the user selects delete all, then all the separate boxes are not checked. I've tried passing back the query from the function which I have in an include file but it doesn't work. Each time the value is passed back it is not set.

    Is there an easier way to do this????

  7. #7
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Not sure I understand. Can't you check the "Delete All" checkbox separately? For example:

    if ($$varname or $deleteall) {
    // delete the thingy...
    }

  8. #8
    SitePoint Enthusiast
    Join Date
    Jun 2000
    Location
    Cork, Ireland
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes you can check the 'delete all' box separately. Unfortunately I cannot tell what the ID of the record each checkbox holds is, because they themselves would not be checked.

    Each checkbox returns the ID value of each record, if it is not checked it returns nothing.

    What I need is a way of checking which records were displayed in the remove form, could I maybe add a hidden value to each record in the form??? then I could access the ID value no matter what, in the next page.

  9. #9
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Ross, refer again to the way I do it my article. Since you are creating your checkboxes from the database, why not use the same list from the database to process the checkboxes?


    ------------------
    -Kevin Yank.
    http://www.SitePoint.com/
    Helping Small Business Grow Online!

  10. #10
    SitePoint Enthusiast
    Join Date
    Jun 2000
    Location
    Cork, Ireland
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Kevin,

    I cannot access the list from the database when the remove form is submitted. But I did find a solution. I added a hidden value containing the ID of each record to the form then I use the same process on the hidden values that I use on the checkbox values when delete all is selected.


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
  •