Re: first Array value duplicating..

From: Date: Thu, 07 Nov 2002 17:05:25 +0000
Subject: Re: first Array value duplicating..
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-23099@lists.php.net to get a copy of this message
An "Real World" example of how I do a similar thing might help: My list with checkboxes (since this is dynamic, I don't know what numbers are assigned) $itemID is the id of the record from the mysql table, so the check box name is 'chk_12' for id=12. $checkAll is a flag if the user selected the "Check All" button, echos("selected") to check all the checkboxes. <td><input type='checkbox' name='chk_$itemID' value='$itemID' $checkAll></td> The in my process code I switch the submit button and test for delete. $maxID is the max(id) from the list of items. I walk through the possible list of items and see if any were checked and if so append them to my list of deletes. Note that I use "where id in ()" to gather all the items at once.
        case "Delete Selected Records":
            for($x=0;$x<=$maxID;$x++){
                $varname="chk_$x";
                $value=$$varname;
                if($value) {
                    $events[] = $value;
                }
            }
            if($events) $events_IDs = implode("','", $events);
            $sql= "delete from $tableName where id in ('$events_IDs')";
            mysql_query($sql) or die($sql . mysql_error());
$message_str="Record(s) deleted";
            break;
HTH Terry On Thursday, November 7, 2002, at 09:24 AM, Aaron Wolski wrote:
Hi All, In a form I have checkboxes associated with order records. The checkboxes are for deleting order records (should a client choose to do so). It looks like this: <form name="form" action="process_bank.php" method="POST">
    <input type="hidden" name="order_index[0]" value="1">
    <td class="cartlink" align="center"><input type="checkbox"
name="delete[0]" value="1"></td>
    <input type="hidden" name="order_index[1]" value="3">
    <td class="cartlink" align="center"><input type="checkbox"
name="delete[1]" value="1"></td>
    <input type="hidden" name="order_index[2]" value="8">
    <td class="cartlink" align="center"><input type="checkbox"
name="delete[2]" value="1"></td>
    <input type="hidden" name="order_index[3]" value="12">
    <td class="cartlink" align="center"><input type="checkbox"
name="delete[3]" value="1"></td> </form> Now.. when the process button is pressed the information is carried off to the process_bank.php script. Lets assume for this example.. I selected the checkbox delete[0] (which equals value 1) and delete[3] (which equals value 12). In the script I have this code: for ($i=0;$i<sizeof($order_index);$i++) { $orderQuery = db_query("SELECT id FROM TestOrderTable WHERE id=".$order_index[$i]); $orderResult = db_fetch($orderQuery); if ($delete[$i] == 1) {
    $ids .= $orderResult["id"];
    echo $ids;
} } The echo'd value that I get is 1,1,12 when it should be 1,12. When only ONE checkbox is selected I just get the one value displayed (i.e. if I selected the first checkbox the echo'd value would be 1). Does anyone know why the first value is being duplicated on a multiple select but not on a single select? Sorry if this sounds confusing :( Aaron


« previous php.db (#23099) next »