RE: mysql delete loop (SOLVED)

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

 



I found that my what I had could actually do the
trick. Basically I didn't know that you could make a
delete statement like this:
DELETE FROM apliexpert WHERE ( id = "2" OR id = "7" OR
id = "1") AND softid = "3"

So my code goes:
#### code ################
for ($index = 0; $index < $total_records; $index++) {
    if (isset($userID[$index])) {
         $sql2 .= " OR id = \"" . $id[$index] . "\"";
    }
}

$sql2 = substr($sql2,3);
$query = "DELETE FROM apliexpert WHERE (" . $sql2 . ")
AND softid = \"$softID\"";
#### end ################

J
--- "Snijders, Mark" <Mark.Snijders@atosorigin.com>
wrote:
> before doing a action, try to print it into the loop
> 
> so try first:  echo "$sql2<br>";
> 
> and you'll see that there is a mistake somewhere i
> guess...
> 
> did you check hhow often he goes trhough the loop?
> 
> 
> 
> -----Original Message-----
> From: Jason End [mailto:bensnephew@yahoo.com]
> Sent: vrijdag 7 maart 2003 11:53
> To: php-db@lists.php.net
> Subject:  mysql delete loop
> 
> 
> 
> displayexpt.php?softID=$softID displays a checkbox
> list of experts for a given piece of software. The
> admin needs to select each user he wants to delete.
> This is then posted to
> deleteexpt.php?softID=$softID,
> which must delete users from the apliexpert table
> with
> a statement like this:
> DELETE FROM apliexpert WHERE id=$id AND
> softID=$softID;
> 
> Given more than one expert may need to be deleted I
> think I need some kind of loop that makes a passes a
> different delete statement for each $id. To handle
> the
> multiple $ids I have the following for loop:
> ##### code ########
> for ($index = 0; $index < $total_records; $index++)
> {
>     if (isset($id[$index])) {
>          $sql2 .= "Clave = \"" . $id[$index] . "\"";
>     }
> ##### end ########
> 
> I've tried changing $sql2 to:
> "DELETE FROM apliexpert WHERE id = \"" . $id[$index]
> .
> "\"";
> 
> but the loop doesn't work; it deletes the first
> record
> and then stops.
> 
> thanks :))
> 
> J
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up
> now.
> http://mailplus.yahoo.com
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

-- 
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