Jump to content

Recommended Posts

Hi,

I have a little database, I can search for records and display them in an html table,

I would like to have a check box of every record returned by the search and a button that onclick will delete the selected records from the database.

 

I am far away from having any idea on where to start on this.

 

Below is my result script:

$host = "localhost"; 
$user = "*****"; 
$pass = "******"; 
$dbname = "contacts"; 

$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>"); 
mysql_select_db($dbname); 


$search = mysql_real_escape_string($_POST['search']);
$result = mysql_query("SELECT * FROM contacts where first_name LIKE '%{$search}%' OR last_name LIKE '%{$search}%' OR company_name LIKE '%{$search}%' OR website LIKE '%{$search}%' OR street LIKE '%{$search}%' OR city LIKE '%{$search}%' OR zip LIKE '%{$search}%' OR country LIKE '%{$search}%' OR mail1 LIKE '%{$search}%' OR mail2 LIKE '%{$search}%' OR phone LIKE '%{$search}%' OR mobile LIKE '%{$search}%' OR card LIKE '%{$search}%' OR birthday LIKE '%{$search}%'") or die (mysql_errno().": ".mysql_error()."<BR>");


echo "<table border=0 width=1400>
<tr bgcolor=#87ceeb font face=tahoma>
<td width=100><b><font face=tahoma>First Name</td><td width=100><b><font face=tahoma>Last Name</td>
<td width=100><b><font face=tahoma>Company Name</td><td width=100><b><font face=tahoma>Website</td>
<td width=100><b><font face=tahoma>Street + Number</td><td width=100><b><font face=tahoma>City</td>
<td width=100><b><font face=tahoma>Post Code</td><td width=100><b><font face=tahoma>Country</td>
<td width=100><b><font face=tahoma>E-Mail 1</td><td width=100><b><font face=tahoma>E-Mail 2</td>
<td width=100><b><font face=tahoma>Phone</td><td width=100><b><font face=tahoma>Mobile</td>
<td width=100><b><font face=tahoma>Christmas Card</td><td width=100><b><font face=tahoma>Birthday</b></td>


</tr>";


while($row = mysql_fetch_array($result)) {  

echo "<tr bgcolor=#4682b4>";
  echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['first_name'] . "</td>";
  echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['last_name'] . "</td>";
  echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['company_name'] . "</td>";
  echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['website'] . "</td>";
  echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['street'] . "</td>";
  echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['city'] . "</td>";
  echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['zip'] . "</td>";
  echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['country'] . "</td>";
  echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['mail1'] . "</td>";
  echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['mail2'] . "</td>";
  echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['phone'] . "</td>";
  echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['mobile'] . "</td>";
  echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['card'] . "</td>";
  echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['birthday'] . "</font></td>";

  echo "</tr>";
  }
echo "</table>";
?>

Try reading some of these threads. People have asked question about this already. They even have some code you can pull from.

Try it out and I'm sure if you have specific questions, someone can help.

 

http://www.phpfreaks.com/forums/index.php/topic,87482.0.html

http://www.phpfreaks.com/forums/index.php/topic,95112.0.html

http://www.phpfreaks.com/forums/index.php/topic,100309.0.html

http://www.phpfreaks.com/forums/index.php/topic,90404.0.html

too tierd to read all that code, but here's a link on how to implement check boxes, sure someone asked how to deal with arrays from forms within last 24 hours on here. My advice is design a little test which makes understanding easy, then apply it to a big wedge o'code like that.

 

mmm Charlie's even just given you some links...

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.