PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > Delete rows from database
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Delete rows from database

Réponse
 
LinkBack Outils de la discussion
Vieux 05/01/2008, 14h03   #1
Balasubramanyam A
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Delete rows from database

Hi all,

I'm searching names from MySQL and printing it on a browser. Also, I've
provided checkbox for all the rows and a delete button for a page. I want to
delete the selected rows from MySQL when I click on the "Delete" button. How
do I do that?

Here is the code which I used to print the rows after fetching the same from
MySQL

while ($line = mysql_fetch_array($resultset, MYSQL_ASSOC)) {
echo "\t<tr>\n";
echo "<td><input type=checkbox name=index /></ td>";
foreach ($line as $col_value) {
echo "\t\t<td>&nbsp;$col_value</td>\n";
}
//echo "<td><input type=button name=vcancel value=Cancel /></td>";
echo "\t</tr>\n";
}

  Réponse avec citation
Vieux 05/01/2008, 14h22   #2
Per Jessen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Delete rows from database

Balasubramanyam A wrote:

> Hi all,
>
> I'm searching names from MySQL and printing it on a browser. Also,
> I've provided checkbox for all the rows and a delete button for a
> page. I want to delete the selected rows from MySQL when I click on
> the "Delete" button. How do I do that?


You process the form that is (presumably) submitted when the user
hits "Delete". In your processing you collect the row-ids or something
else you can use in the <whereclause> : "DELETE FROM table WHERE
<whereclause>".


/Per Jessen, Zürich
  Réponse avec citation
Vieux 05/01/2008, 15h40   #3
Daniel Brown
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Delete rows from database

On Jan 5, 2008 9:03 AM, Balasubramanyam A <knowledge.wealth@gmail.com> wrote:
> Hi all,


Hi!

[snip]

> while ($line = mysql_fetch_array($resultset, MYSQL_ASSOC)) {

[snip]

Just a side note: wouldn't it be easier to just use
mysql_fetch_assoc() ? It does the exact same thing, with less typing.


--
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]

If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.
  Réponse avec citation
Vieux 07/01/2008, 08h59   #4
Jim Lucas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Delete rows from database

Balasubramanyam A wrote:
> Hi all,
>
> I'm searching names from MySQL and printing it on a browser. Also, I've
> provided checkbox for all the rows and a delete button for a page. I want to
> delete the selected rows from MySQL when I click on the "Delete" button. How
> do I do that?
>
> Here is the code which I used to print the rows after fetching the same from
> MySQL
>
> while ($line = mysql_fetch_array($resultset, MYSQL_ASSOC)) {
> echo "\t<tr>\n";
> echo "<td><input type=checkbox name=index /></ td>";


In the above line you need to have the row ID as the value of your check
box. Also, you should probably use and array in your form. See below
for example and explanation.

echo "<td><input type=checkbox name=delete[] value={$line['id']} /></ td>";


Ok, broken down...

nothing special about this, pretty standard
echo "<td><input type=checkbox

This, when submitted to PHP, will create an array in the POST/GET array
name=delete[]

This will assign the value of ID to the checkbox array
value={$line['id']}

etc...

Now, this is assuming that your id column is called ID and that you will
be wanting to delete more then one at a time.

on the process page, do a print_r($_POST)

You will see what you get

> foreach ($line as $col_value) {
> echo "\t\t<td>&nbsp;$col_value</td>\n";
> }
> //echo "<td><input type=button name=vcancel value=Cancel /></td>";
> echo "\t</tr>\n";
> }
>

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h55.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11107 seconds with 12 queries