SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: Whats Wrong?

  1. #1
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Whats Wrong?

    I can't seem to figure out why this is not working properly. The first page is a form with checkboxes and then a textbox for quantity. (www.soupladle.com/order.php). The second box of code here is the results of that form, but in a summary printable format.

    Form:
    PHP Code:
    while( $list mysql_fetch_array$query ) )
    {
        
    $soupCheckboxes .='<tr><td><font face="verdana" size="2" color="#000000"><input type="checkbox" name="SoupName[]" value="' 
                        
    $list["SoupName"]
                        . 
    '">' 
                        
    htmlspecialchars($list["SoupName"]) 
                        . 
    '</td>'
                        
    '<td><font face="verdana" size="2" color="#000000"><input type="text" size="3" name="Cup[]"></td>'
                        
    '<td><font face="verdana" size="2" color="#000000"><input type="text" size="3" name="Bowl[]"></td>'
                        
    '<td><font face="verdana" size="2" color="#000000"><input type="text" size="3" name="Mulloy[]">' 
                        
    '</tr>';
    }
    echo (
    $soupCheckboxes); 
    Result:
    PHP Code:
    $soupName $_POST['SoupName'];
    $cup $_POST['Cup'];
    $bowl $_POST['Bowl'];
    $mulloy $_POST['Mulloy'];
    $count count($soupName);
    //example
    echo '<table border="0" width="40%"><tr><td><font size="2"><b>Soup Name</b></td><td><font size="2"><b>Cups</b></td><td><font size="2"><b>Bowls</b></td><td><font size="2"><b>Mulloy</b></td></tr>';
    for (
    $i 0$i $count$i++)
    {
        echo 
    '<tr>';
        echo 
    '<td><font size=2> ' $soupName[$i] . '</td>';
        echo 
    '<td><font size=2> ' $cup[$i]      . '</td>';
        echo 
    '<td><font size=2> ' $bowl[$i]      . '</td>';
        echo 
    '<td><font size=2> ' $mulloy[$i]     . '</td>'
        echo 
    '</tr>';   

    The result always returns the names of the soups checked, but not the quantity entered in the textbox. What is wrong here? Try it out if you don't understand it. www.soupladle.com/order.php
    TAKE A WALK OUTSIDE YOUR MIND.

  2. #2
    SitePoint Member
    Join Date
    Apr 2003
    Location
    interNET
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should use a numeric index instead of just [] in submit form:

    PHP Code:
    $i=0;
    while( 
    $list mysql_fetch_array$query ) )
    {
        
    $soupCheckboxes .='<tr><td><font face="verdana" size="2" color="#000000"><input type="checkbox" name="SoupName['.$i.']" value="' 
                        
    $list["SoupName"]
                        . 
    '">' 
                        
    htmlspecialchars($list["SoupName"]) 
                        . 
    '</td>'
                        
    '<td><font face="verdana" size="2" color="#000000"><input type="text" size="3" name="Cup['.$i.']"></td>'
                        
    '<td><font face="verdana" size="2" color="#000000"><input type="text" size="3" name="Bowl['.$i.']"></td>'
                        
    '<td><font face="verdana" size="2" color="#000000"><input type="text" size="3" name="Mulloy['.$i.']">' 
                        
    '</tr>';
    $i++;
    }
    echo (
    $soupCheckboxes); 

  3. #3
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by VisualMind
    You should use a numeric index instead of just [] in submit form:
    Why? I never have and I've never had any problems.

  4. #4
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    I am not really sure that is the problem anymore. This is kinda difficult to explain, so if you need to try it out yourself the link is http://www.soupladle.com/order.php.

    Each row (soup name and qty) is pulled from the database by current date. The # of soups and names changes daily, so this is the best option. If I "check" the second and third soup, and enter different quantites (easier to see what is going on), you can see that things are not lining up correctly. It is really weird.

    How can I fix this? It seems like each qty row falls on top of each other regardless if there is a value or not and the soupnames are only showing up if they are checked. This misaligns everything!

    If you understood what I just said, how can I fix this?
    TAKE A WALK OUTSIDE YOUR MIND.

  5. #5
    SitePoint Member
    Join Date
    Apr 2003
    Location
    interNET
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DJ P@CkMaN
    Why? I never have and I've never had any problems.
    Ok let me explain why.. the guy need the names (in checkboxes) be submited with the quantities entered near them, SO look at this:

    Code:
    Name            Type           value
    =========================
    SoupName[]   checkbox   Chicken Parmesan
    Cup[]            textbox     
    Mulloy[]         textbox     
    SoupName[]   checkbox   Minestrone
    Cup[]            textbox     
    Mulloy[]         textbox     
    SoupName[]   checkbox   Cream of Wild Mushroom
    Cup[]            textbox     
    Mulloy[]         textbox
    If the user checked both of "Chicken Parmesan" and "Minestrone" and submited there will be no problem because SoupName[0] will be "Chicken Parmesan" and its quantity Cup[0] will have the right value and same for "Minestrone" SoupName[1]="Minestrone" and its quantity Cup[1].
    BUT If the user checked "Chicken Parmesan" and "Cream of Wild Mushroom" leaving "Minestrone" unchecked this means:
    SoupName[0] = "Chicken Parmesan" and it's quantity Cup[0] - right
    SoupName[1] = "Cream of Wild Mushroom" and it's quantities Cup[1] is wrong! u should ask about Cup[2] !
    but if u give numeric index it will be easy to find the correct quantity for the correct SoupName

    CHECKBOXes' values aren't being sent if they're not checked so the array will not be the same if u didn't check all..


    hyperbolik, Did you try my idea of using numeric index for all of ur inputs? and btw you should also use foreach instead of just (for) like this:
    PHP Code:
    $SoupName $_POST['SoupName'];
    $cup $_POST['Cup'];
    $bowl $_POST['Bowl'];
    $mulloy $_POST['Mulloy'];
    //example
    echo '<table border="0" width="40%"><tr><td><font size="2"><b>Soup Name</b></td><td><font size="2"><b>Cups</b></td><td><font size="2"><b>Bowls</b></td><td><font size="2"><b>Mulloy</b></td></tr>';
    foreach (
    $SoupName as $i=>$Soup
    {
        echo 
    '<tr>';
        echo 
    '<td><font size=2> ' $Soup '</td>';
        echo 
    '<td><font size=2> ' $cup[$i]      . '</td>';
        echo 
    '<td><font size=2> ' $bowl[$i]      . '</td>';
        echo 
    '<td><font size=2> ' $mulloy[$i]     . '</td>'
        echo 
    '</tr>';   


  6. #6
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Yes, I tried it, but it only made things stranger. It seems like every checkbox needs to be checked for it to work.
    TAKE A WALK OUTSIDE YOUR MIND.

  7. #7
    SitePoint Member
    Join Date
    Apr 2003
    Location
    interNET
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    even after using foreach? I've just edited my reply while u were adding ur reply, not sure if u've seen the comment about foreach

  8. #8
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    You are a genius. Thanks so much. It works flawlessly!

    THANK YOU!
    TAKE A WALK OUTSIDE YOUR MIND.

  9. #9
    SitePoint Member
    Join Date
    Apr 2003
    Location
    interNET
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    welcome


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
  •