Re: first Array value duplicating..

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ok, here's how I do it: =)

Delete checkbox's (assuming this is being called recursively, once
for each row in the db):

<input type="checkbox" name="delete[]" value="$row[id]">

And on submition:

foreach($_POST[delete] AS $row)
	mysql_query("DELETE FROM tablename WHERE id = '$row';");

Adam Voigt
adam.voigt@cryptocomm.com

> > 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
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 



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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux