Jump to content

Recommended Posts

current i show mysql data in a table aim to make my own datagrid.

but how to adding the delete feature by tick the checkbox and then press the "delete" button, then it will delete the record in mysql db too?

and how to add the effect that when click on the record..then highlight the table's row?

bellow is the screenshot of my datagrid ..

datagridpc8.jpg

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/75223-my-own-datagrid-problem/
Share on other sites

You'd name all of your checkboxes the same thing:

name="delete[]"

The [] ensures that the checked boxes are sent as an array. Don't forget to give them unique values, a good choice would be the id of the row in the database.

 

When processing, you can then just loop through your POSTed array and create a query:

<?php
$q = "DELETE FROM `table` WHERE ";
foreach($_POST['delete'] as $id) $q .= "`id`='$id' AND ";
$q = substr($q,0,-5);
mysql_query($q) or die(mysql_error());
?>

 

As far as highlighting a row, not sure, JavaScript?

You'd name all of your checkboxes the same thing:

name="delete[]"

The [] ensures that the checked boxes are sent as an array. Don't forget to give them unique values, a good choice would be the id of the row in the database.

 

When processing, you can then just loop through your POSTed array and create a query:

<?php
$q = "DELETE FROM `table` WHERE ";
foreach($_POST['delete'] as $id) $q .= "`id`='$id' AND ";
$q = substr($q,0,-5);
mysql_query($q) or die(mysql_error());
?>

 

 

As far as highlighting a row, not sure, JavaScript?

$_POST['delete'] as $id y use "as", wat it for? thanks..

For the Edit you could create a sepeate page and in the link add ?rec=$ID

where $ID is the reord number. Same as you would do for the value of the check boxes. Then create a (php only) update page, and redirct back to your table.

 

Desmond

thanks for your help

 

do u got tutorial about this edit, or wat keyword should i google? fail to find it several time.

 

?rec=$ID <--this is get method?

 

When processing, you can then just loop through your POSTed array and create a query:

<?php
$q = "DELETE FROM `table` WHERE ";
foreach($_POST['delete'] as $id) $q .= "`id`='$id' AND ";
$q = substr($q,0,-5);
mysql_query($q) or die(mysql_error());
?>

 

Hmm! Think you meant 'OR' instead of 'AND'.

 

Alternative

<?php
$ids = join (',', $_POST['delete'])
$q = "DELETE FROM table WHERE id IN ($ids)"; 

For the Edit you could create a sepeate page and in the link add ?rec=$ID

where $ID is the reord number. Same as you would do for the value of the check boxes. Then create a (php only) update page, and redirct back to your table.

 

Desmond

 

where can i learn this ink add ?rec=$ID

where $ID is the reord number.???

wat this technique called?

i wanna go research for it.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.