Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

how can I delete athletes from my database

Posted on 2012-09-09
9
Medium Priority
?
288 Views
Last Modified: 2012-09-13
Hi I need to be able to add a delete colum to my display table shown below, so that I can successfully remove any number of athletes. I would then like to be able to provide some feedback that the athletes where successfully removed. Please help as I'm new to this and I'm struggling to understand it all
<?php

include 'assignment2Connect.inc.php';

$query = "SELECT image, lname, fname, gender, sport, name FROM tblolympicAthletes
                  JOIN tblCountry ON (tblolympicAthletes.countrynationcodeID = tblCountry.countrynationcodeID)
order by lname";
$result = mysql_query($query);

echo"<table>";
echo"<tr><th>Image</th><th>Last Name</th><th>First Name</th><th>Gender</th><th>sport</th><th>Country</th></tr>";
while ($row = mysql_fetch_assoc($result))
{
      echo("<tr>");
      foreach($row as $index=>$value)
      {
      if ($index == 'image')
            {
                  echo("<td><img src=$value /></td>");
            }
            else
            {
                  echo("<td>$value</td>");
            }
            }
                  echo("</tr>");
            
}
echo("</table>");
?>

Also here is my Athlete table

include 'assignment2Connect.inc.php';

$createTable = "DROP TABLE IF EXISTS tblolympicAthletes";
$result = mysql_query($createTable);

$createTable = "create table tblolympicAthletes
(
athleteID  int(6) not null auto_increment,
image   varchar(20) not null,
lname      varchar(20) not null,
fname      varchar(20) not null,
gender      varchar(1) not null,
sport      varchar(50) not null,
countrynationcodeID int(5) not null,

PRIMARY KEY(athleteID)
)";

$result = mysql_query($createTable);

function createRecordA ($image, $lname, $fname, $gender, $sport, $countrynationcodeID)
{
$insertQuery = "insert into tblolympicAthletes (image, lname, fname, gender, sport, countrynationcodeID) values ('$image', '$lname',
'$fname', '$gender', '$sport', '$countrynationcodeID')";
$result = mysql_query($insertQuery);
}
createRecordA('dan.jpg alt=dan', 'Olaru', 'Dan', 'M', 'Archery', '1');
createRecordA('Gemma.jpg alt=gemma', 'Flynn', 'Gemma', 'F', 'Hockey', '2');
createRecordA('Sona.jpg alt=sona', 'Bernardova', 'Sona', 'F', 'Synchronised-swimming', '3');
createRecordA('Robert.jpg alt=robert', 'Elder', 'Robert', 'M', 'Archery', '4');
createRecordA('Gian.jpg alt=gian', 'Sibello', 'Gianfranco', 'M', 'Sailing', '5');
createRecordA('Charlotte.jpg alt=charlotte', 'Harrison', 'Charlotte', 'F', 'Hockey', '2');
createRecordA('Anne-marie.jpg alt=anne-marie',  'Rindom', 'Anne-Marie', 'F', 'Sailing', '6');
createRecordA('Anna.jpg alt=anna', 'Kulkina', 'Anna', 'F', 'Synchronised-swimming', '7');
createRecordA('C.jpg alt=c', 'Eskilsson', 'Christofer', 'M', 'Diving', '8');
createRecordA('Ger.jpg alt=ger',  'Owens', 'Ger', 'M', 'Sailing', '9');
createRecordA('Katie.jpg alt=katie',  'Skelton', 'Katie', 'F', 'Synchronised-swimming', '10');
createRecordA('Emily.jpg alt=emily',  'Naylor', 'Emily', 'F', 'Hockey', '2');
createRecordA('Anna1.jpg alt=anna',  'Pysmenska', 'Anna', 'F', 'Diving', '11');
createRecordA('Xi.jpg alt=xi',  'Dai', 'Xiaoxiang', 'M', 'Archery', '12');
createRecordA('Olena.jpg alt=olena',  'Fedorova', 'Olena', 'F', 'Diving', '11');

Cheers
0
Comment
Question by:stumpboss
  • 5
  • 4
9 Comments
 
LVL 27

Accepted Solution

by:
Cornelia Yoder earned 1000 total points
ID: 38381560
stumpboss, I hate to throw cold water on your question, but the rules of EE prohibit experts from helping you do a scholastic assignment in this blanket way.

We are allowed to answer specific questions if you can rephrase to ask about some point where you are having trouble, but not to guide you step by step through your assignment.
0
 

Author Comment

by:stumpboss
ID: 38381609
ok sorry didn't  think I was doing that, just wanted some help with one piece of the puzzle
0
 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 38381647
Which specific piece and what is your question about it?
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

Author Comment

by:stumpboss
ID: 38381652
how do I add a delete radio button to my table
0
 
LVL 27

Assisted Solution

by:Cornelia Yoder
Cornelia Yoder earned 1000 total points
ID: 38381704
You have a database "table" and an html "table".  I'm assuming you want to add a delete button to the html table where you are displaying the info to some user.  Right?  And then when that button is pushed, you want to remove that athlete from the database table?

You will need to create a "form" and a submit button.  The submit button will say "Delete" on it, and the form will contain a hidden input with the athlete id for that athlete, so when the button is clicked, the form is triggered and the id of that athlete passed to your form processing action script.

Start by reading about <form and how it works.  Then create a <form within the html table row for each athlete.  Within the form, put a hidden input and a submit button.

In the action script that the form triggers, retrieve that input, use the id to delete from your database, and then echo out a confirmation message.

Things to read about:
html <form .....
html <input type=hidden ....
html <input type=submit ....
php array $_POST
MySQL DELETE
php echo
0
 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 38381708
If you want to get a little more sophisticated, you can use checkboxes for each athlete and a single submit button to delete all the checked ones.  (Read about <input type=checkbox)

You could use a radio button to select exactly one of the athletes if you really want a radio button, instead of a form in each line of the table (Read about <input type=radio)
0
 

Author Comment

by:stumpboss
ID: 38382505
Thanks for the info I've looked around at all your suggestions and had ago at it, but still I'm unable to accomplish it

This is the result I get
0
 

Author Comment

by:stumpboss
ID: 38382527
what I really need is the  th along the top and all records displayed in the td like this

lname               fname            gender            sport             country              population          delete

mike                 may                   m                    ......               ........                      .......             checkbox

Then I would be able to select the athletes to delete as you suggested earlier can you give me any clues please
0
 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 38382626
Clue:  Read about formating HTML tables, in particular how to use the <table>, <tr> and <td> tags to format it the way you want it to look.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating and Managing Databases with phpMyAdmin in cPanel.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question