Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 05-16-2007, 12:35 AM   #1 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
Record Delete Button

Alloha,

I currently have 3 fields in a database, these are the following:
  • Name
  • Sex
  • Age

How do I display all records in the database, and place a delete button next to each one. Upon the user clicking the button the associated record gets deleted and the page is refreshed to reflect the this action?

Many Thanks,
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 05-16-2007, 08:08 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
people here are pretty open to newbie questions, but by now i'd think you have been developing with HTML/PHP/MySQL enough to get something started and show us where you're stuck. maybe just tell us ways you are considering going about it.

no offense, but i avoid your 'how do i' questions now because most of them don't show more effort on your part than it would take to answer your question. by the looks of your un-answered posts, it seems like others may feel the same way too.

don't take it as a flame, but i personally think you could answer most of the pieces that make up your question.

- How do I display all records in the database?
- How do I place a button next to each of these records?
- How do I do I make each button send POST or GET info?
- How do I handle the POST or GET info that the button sends?
- How do I delete the record in the database?
- How do I display all the records in the database now?
__________________
Mike
sde is offline   Reply With Quote
Old 05-16-2007, 08:12 AM   #3 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 673
DJMaze is on a distinguished road
PHP Code:
$sql mysql_query('SHOW * FROM samples WHERE user_name=\'Salchester\'');
while (
mysql_fetch_row($sql))
{
    echo 
'<button name="delete" value="sample_id">delete</button>';

But it wouldn't show any buttons cos there are no samples given yet.
Nor does the above code work, it's a quest.
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 07-01-2007, 07:46 AM   #4 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
Record Delete Button

DJMaze,

I have come up with the following code, that displays each record with it's own check box. Though how do I assign the "Numeric Array Store" value of each record to each check box, so when the delete button is clicked, the code knows which record in the $records array to NOT copy into the $temp array?

Upon a record being selected and the delete button being clicked, how do I copy all but the selected records to a $temp array, from the $records array?

Code:
<?php
$con = mysql_connect("localhost","peter","abc123");

if (!$con)
{
  die('Could not connect: ' . mysql_error());
}

mysql_select_db("WB", $con);

$result = mysql_query("SELECT * FROM Birds");

if(mysql_error() != 0 || mysql_num_rows($result) == 0)
{
  die("No database, or no data");
}

$records = array();
$temp = array();
while($row = mysql_fetch_object($result))
{
  array_push($records, $row);
}

$i = 0;

foreach( $records as $k )
{
  echo "$k->Name";
  echo "$k->Species";
  echo "$k->Sex";
  echo "<input type='checkbox' name='remove[" .$i. "]' value=" .$i. " />\n"; 
  $i++;
}

echo "<input type='submit' value='Delete' />\n";
?>
Many Thanks,
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 07-01-2007, 11:52 PM   #5 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 673
DJMaze is on a distinguished road
You can't.
Learn those god damn primary id's as was told to you 100 times, you fool.

After that you know the answer of this topic.
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Reply

Bookmarks

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
File I/O and arrays JaySun Standard C, C++ 6 03-24-2005 10:43 PM
drawing shapes in any diagonal direction in applet davidmccabe Java 3 03-17-2005 02:53 AM
Internet speed record quadrupled to 101 Gbit/s sde Code Newbie News 0 11-30-2004 09:01 AM
Need help with C++ ewic Standard C, C++ 7 10-01-2004 04:24 AM
getting the value of a select box to confirm delete. sde HTML, XML, Javascript, AJAX 2 05-03-2004 08:40 AM


All times are GMT -8. The time now is 09:15 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting