Current location: Hot Scripts Forums » Programming Languages » PHP » Deleting one entry on dynamic table


Deleting one entry on dynamic table

Reply
  #1 (permalink)  
Old 04-19-04, 02:08 PM
Bonzo's Avatar
Bonzo Bonzo is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
Deleting one entry on dynamic table

All very messy and NeverMind will probably complain : )

I am generating a image table from an array - This works OK

Now I want to select a " check box " ( or more than one ) to delete that entry.

All that happens is the last entry in the table comes up for deletion every time !
PHP Code:

echo "<td align='center'><a href = display.php?pic=$row[image] target=_blank>

        <img src = thumb/
$row[image].JPG alt=$row[image]></a>
        <FORM ACTION = 'delete.php' METHOD = POST>
        <INPUT TYPE=HIDDEN input NAME=delete value='
$row[image].JPG'>
        <INPUT TYPE='CHECKBOX'>
        </td> 
Can someone tell me where I am going wrong.

Anthony
Reply With Quote
  #2 (permalink)  
Old 04-19-04, 02:36 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
HEY!!
I don't usualy complain unless something worth complaining happen
anyway the form should be started before the loop of the table elements!
and you don't need to have a hidden input for that !
the checkbox itself should have the value (name of image)..
and one note, I think many browser will complain (not me!) about this messed up HTML syntax !! it will work but it's really messed up ! sometimes you use single quotes sometimes you don't sometimes you use spaces and sometimes not !!
have a coding standered, it will help You in maintaining your code !
like this:
PHP Code:

echo'<FORM ACTION="delete.php" METHOD="POST">';


//LOOP OF TABLE (if there was one)
//one element of the table:
echo '<td align="center"><input type="checkbox" name="delete[]" value="'.$row['image'].'.JPG" />
<a href="display.php?pic='
.$row['image'].'" target="_blank"> 
<img border="0" src="thumb/'
.$row['image'].'.JPG" alt="'.$row['image'].'"></a> 
this code shall make an array containing all images' names that will be deleted ..
so loop through the array and DELETE FROM table ..
PHP Code:

$delete = array();

$delete $_POST['delete'];

for (
$i=0$i<count($delete); $i++) {
  
mysql_query("DELETE FROM table_1 WHERE image='$delete[$i]'")or
  die(
mysql_error());

__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
auto table resize derick_2k JavaScript 4 04-26-04 02:32 PM
need help in sorting table niyax JavaScript 1 03-24-04 03:39 AM
Newbie MySQL fccolon PHP 2 03-16-04 10:54 AM
SQL for deleting 'one' table records in one-to-many relationship lanewalk Visual Basic 1 12-23-03 06:28 AM
moving data from table to table ..please help! geneane ASP 2 09-22-03 07:02 PM


All times are GMT -5. The time now is 10:27 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.