www.webdeveloper.com
Results 1 to 2 of 2

Thread: Compare checked values

Hybrid View

  1. #1
    Join Date
    Apr 2010
    Posts
    5

    Compare checked values

    Hi there!

    I tried finding my answer by searching through posts, so far no luck, so I'm hoping anyone of you can help me out on this one. At the moment I'm working on a invoice page, before you can invoice you need an order, but each invoice you make may contain multiple orders.

    What I've got, A while loop that shows all non invoiced orders with a checkbox in front of it. When you check multiple checkboxes it first has to check if the customer ID (klant_id) is the same, you can't raise 1 invoice for 2 different customers. So far my script can tell me if I selected 2 different customers or 2 the same.

    The problem is, when I for example select the 2nd or 3rd checkbox it won't show me which order ID or customer ID I selected, only if I select the 1st checkbox.

    Thank you in advance.

    PHP Code:
    if(!empty($_POST['action']))
    {

    $value 'empty';
    $i 1;
    while(isset(
    $_POST['klant_id'.$i]))
    {
      
      if(
    $value == "empty")
      {
      
    $value $_POST['klant_id'.$i];
      }
      
      if(
    $_POST['klant_id'.$i] != $value )
      {
      die(
    "<br><br>It is not possbile to raise an invoice for different customers.");
      }


    echo 
    "Customer ID: " $_POST['klant_id'.$i] . " Order ID: " $_POST['order_id'.$i] . "<br>";

    $i++;
    }
    echo 
    "<br><br>SUCCES!!<br>";
    }
    ?> 
    Code:
    $i = 1;
    while($dbinfo = mysql_fetch_assoc($res)) { 
    
    <input type="checkbox" name="klant_id<?=$i;?>" value="<?=$dbinfo['klant_id'];?>" />
    <input type="hidden" name="order_id<?=$i;?>" value="<?=$dbinfo['order_id']?>">
    
    <?php $i++; }?>

  2. #2
    Join Date
    Apr 2010
    Posts
    5
    Sorry for the trouble, I think I already solved it.

    PHP Code:
    <?php
    $i 
    1;
    foreach(
    $_POST['order_id'] as $id => $order_id)
    {
    $sql "SELECT * FROM `order` WHERE order_id = '".$order_id."' AND klant_id = '".$_POST['klant_id'][$i]."'";
    $res mysql_query($sql) or die (mysql_error());
    $row mysql_fetch_array($res);

    if(
    $row['klant_id'] != $_POST['klant_id'][$i--]) { die("You selected 2 different customers"); }


    //echo "Order ID: " . $row['order_id'] . " Klant ID: " . $row['klant_id'] . "<br>";
    $i++;
    }
    ?>
    Code:
    
    <?php
    $order_sql = "SELECT * FROM `order` ORDER BY gefactureerd ASC, order_id ASC";
    $order_res = mysql_query($order_sql);
    
    $i = 1;
    while($dbinfo = mysql_fetch_assoc($order_res)) { 
    ?>
    
    
    <input type="checkbox" name="order_id[<?=$i;?>]" value="<?=$dbinfo['order_id'];?>" />
    <input type="hidden" name="klant_id[<?=$i;?>]" value="<?=$dbinfo['klant_id']?>">
    
    <?php $i++; }?>	

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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