Page 1 of 1

deleting multiple data from sql using .tpl files

Posted: Mon Sep 25, 2006 3:39 pm
by texxarse
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


i've got a little problem...
i'm actually new in php coding and i can't get some things, some things i can't understand. i'm begging for help for the first time...
i got the code which displays records from database(MySQL) like:

Code: Select all

// displaying records
for ($i = 0; $i < count($this->mMessage); $i++)
  $this->mMessage[$i]['onclick'] = "index.php?MailAccountID=2&SentMessageID=" . $this->mMessage[$i]['sent_id'];
// end of displaying
// deleting data
if(isset($_POST['Delete']))
{
  $query_string = "DELETE FROM sent WHERE sent_id = '$this->mSelectedMessage' AND customer_id = '$this->mCustomer' LIMIT 1";
  $result = @mysql_query($query_string);
  header("Location: index.php?MailAccountID=2");
  exit;
}
// end of this code
and it's working perfectly but it can delete just one record. i want to delete multiple data using checkboxes. actually i already placed them in table where records are being displayed but the don't work... :(
can someone halp me? i want to have same code but with ability to delete multiple data

thnx a lot
texxarse


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Sep 25, 2006 5:18 pm
by sojos
I don't have all your code and so I probably miss something. My proposal to submit a bunch of selected checkboxes to a php script is to use the following attributes in the input tag:

Code: Select all

<form method="POST" action="">
<input type="checkbox" name="id[]" value="1">Record 1<br>
<input type="checkbox" name="id[]" value="2">Record 2<br>
...
<input type="submit" name="Delete" value="Delete them!">
</form>
And evaluate it like this:

Code: Select all

if (isset($_POST["Delete"] {
  foreach ($_POST['id'] as $k => $v) {
    mysql_query("DELETE FROM ... WHERE id = $v ...");
  }
}

Re: deleting multiple data from sql using .tpl files

Posted: Tue Sep 26, 2006 2:27 am
by Mordred
You can't delete data using .tpl files. For that you need .del files.

Hint:
texxarse wrote:i've got a little problem...
i'm actually new in php coding and i can't get some things, some things i can't understand. i'm begging for help for the first time...
Fine, but is that an excuse for not writing a proper subject line?