Hello All,

I have developed a system to retrieve data from a table. The interface is a
dynamic list of orders created from a query on the database that shows all
the new orders. Next to each is a checkbox. Each checkbox has as its value
the order number and is called PED1, PED2, PED3,....PEDn,.... depending on
how many new orders are available. If the user wants to access these orders
he has to check the orders he wants and click the submit button. Once it is
submited, it searches all the PED# variables on the HTTP_POST_VARS and
builds an array called $Orders. The $Orders array contains order numbers and
is later used to query a different table.

Ths code works almost great. But there is a problem, if the first checkbox,
say PED1 field is not checked, and some of the other checkboxes are (say
PED2, PED4), the $Orders array ends being empty. So, say that the form has 5
orders and the user selects orders 2, 4 and 5 and submit it. It does not
work. But if he selects 1,2, 4 and 5 it works. It works only if the first
checkbox is checked too.

What I wonder is why this code does not work if PED1 checkbox is not
checked. What if the user only wants other stuff but the first order PED1?

Could you help me on this?

Here's the code:

This is a function that searches for variables called PED1, PED2, PED3 that
are checkboxes on a submited form and have the order numbers. When this
checkbox is checked, the ordernumber is saved on an Array $Orders that is
later used to build a SQL statement.

function SearchOrders() {
    global $Orders;
    global $HTTP_POST_VARS;

 $index = count($HTTP_POST_VARS);

 for($i=1; $i <= $index; $i++) {
     if (isset($HTTP_POST_VARS["PED$i"]))
     $Orders[] = $HTTP_POST_VARS["PED$i"];
 $index = count($Orders);
 return $index;


This is a function that retrieves the array values that are order numbers
from the array $Orders and assembles a SQL statement $query.
This will later retrieve data from a MySQL table;

function MontarOrdRel() {
    global $Orders;

 $query = "SELECT  *  FROM tbl_Ord ";

if (count($Orders) > 0)
     $query .= "WHERE ";

 for($index=0; $index < count($Orders); $index++) {

     if ($index < (count($Orders)-1)) {
  $query .="(NumPedido = '".$Orders[$index]."') OR ";
     else {
  $query .="(NumPedido = '".$Orders[$index]."') ";
 } // for loop
 $query .= "ORDER BY NumOrd";

Then $query is used to query a table.

Thank you for your help,

Carlos Fernando Scheidecker Antunes.

Linux User #207984

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to