$_POST Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jazon
    New Member
    • Apr 2007
    • 5

    $_POST Help

    Ok, I'm having a really tough time getting this to work the way I want.

    Page One

    [PHP]
    <? while ($row = mysql_fetch_arr ay($result)){ ?>

    <tr>

    <td><input type="text" name="lots[]" size="13" maxlength="12" value=""></td>

    <td><input type="checkbox" name="tanks[]" value="<? echo("$row[serial]"); ?>"></td>

    </tr>

    <? } ?>

    [/PHP]


    Page Two
    [PHP]
    <?
    $howmany = count($_POST['tanks']);
    if ($howmany > 0){
    foreach($_POST['tanks'] as $serial => $tank){
    //Whatever
    }
    }
    ?>
    [/PHP]

    Yay, page two works fine.

    BUT, What I really want to do is Make it so that I can make an SQL query with both the lot and serial on page two.

    Such as $query = SELECT * FROM 'whatever' WHERE lot = lots[] and tank = tanks[]

    And, I have absolutely no idea how to go about doing this.

    Does that make much sense? Please let me know if I need to clarify anything. I'm really confused and very new to this.
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    The foreach loop is a shorthand convenient format of the for loop. Do not forget what is behind it.

    $tanks = $_POST['tanks'];
    $lots = $_POST['lots'];

    for($c=0;$c<siz eof($lots);$c++ ){
    $lot = $lots[$c];
    $lot = $lots[$c];

    as $serial => $tank){
    //Whatever
    }
    }
    ?>

    Such as $query = SELECT * FROM 'whatever' WHERE lot = lots[] and tank = tanks[]

    Comment

    • code green
      Recognized Expert Top Contributor
      • Mar 2007
      • 1726

      #3
      Ignore last. False submission

      [PHP]$tanks = $_POST['tanks'];
      $lots = $_POST['lots'];

      for($c=0;$c<siz eof($lots);$c++ ){

      $query = "SELECT * FROM 'whatever'
      WHERE lot = $lots[$c] AND tank = $tanks[$c]";
      }[/PHP]
      You may need curly brackets around the array variables in the SELECT string

      Comment

      Working...