Jump to content


Photo

PHP MySQL Alter and Delete Script


  • Please log in to reply
2 replies to this topic

#1 Darno

Darno
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 09 September 2006 - 01:40 PM

Sir/Ma'am,

    I'm newbie programmer in php. I'm working with a Purchasing System using a php and MySQL. I have created a delete script in a said System but it could only delete 1 record...Please give some suggestions or ideas on How do I delete a record one by one and give some scripts in altering a record..tnx a lot.. :) 

#2 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 10 September 2006 - 09:50 AM

Your question is not at all clear to me.

You state that you have been able to delete a record. So you know how to do this. Just repeat it (with a different WHERE clause of course) for the other records you want to delete.

About altering: you can ALTER a database or ALTER a table, but what do you mean by ALTERing a row?

Ronald  8)
RTFM is an almost extinct art form, it should be subsidized.

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 10 September 2006 - 02:52 PM

Suppose you have listed several items from a table, and have a checkbox on each row to indicate which items are to be deleted
[pre]
Item              Qty        Delete

Widget            25          (x)
Wotsit              1          ( )
Gizmo              10          (x)

                (Delete selected)[/pre]
               
Define each c/box with a name ending with "[]" and with a value = the id of the listed item
EG
echo "<input type='checkbox' name='delitem[]' value='$id'>";

When the form is submitted you want to create a query like

DELETE FROM item WHERE id IN (1,3)

which will delete the 2 items shown above.

<?php
$items = join (',' , $_POST['delitem']);
mysql_query ("DELETE FROM item WHERE id IN ($items)");

echo "Selected items deleted";
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users