Jump to content
php.lv forumi

delete from tabula


Klez

Recommended Posts

vai no tabulas ir iespeejams ar vienu query izdzeest vairaakus ierakstus peec ID

DB = mysql 4.0.23

ID tabulaa ir int autoIncrement

 

id | val

1 a

2 b

3 dd

4 ff

 

gribu izdzeest 1 un 3 ierakstu ar vienu query. bet zinaams ir tikai ieraksta ID

 

ir tas paveicams?

Link to comment
Share on other sites

DELETE FROM tabula WHERE id IN(1,3)

NB: ja ģenerē att. checkbox-inpututus

 

while (...fetch...)

<input type="checkbox" name="todelete[]" value=" $id " />

 

tad var ērti izmantot

 

'DELETE FROM tabula WHERE id IN('. implode(',', $_POST['todelete']).')'

 

variantu

Link to comment
Share on other sites

Klez, tik atceries: neuzticies lietotāja datiem!!!

Pirms laid to implode uz $_POST masīva elementu, izej viņam cauri un pārliecinies, ka visas vērtības ir integer!

DELETE FROM tabula WHERE id IN('.  implode(',', array_map("intval", $_POST['todelete'])).')'

Edited by bubu
Link to comment
Share on other sites

×
×
  • Create New...