colleyboy Posted July 6, 2010 Share Posted July 6, 2010 Hiya... This code below displays the database table "contacts": <? include("dbinfo.inc.php"); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM contacts"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Database Output</center></b><br><br>"; ?> <table border="0" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif">Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Phone</font></th> <th><font face="Arial, Helvetica, sans-serif">Mobile</font></th> <th><font face="Arial, Helvetica, sans-serif">Fax</font></th> <th><font face="Arial, Helvetica, sans-serif">E-mail</font></th> <th><font face="Arial, Helvetica, sans-serif">Website</font></th> </tr> <? $i=0; while ($i < $num) { $first=mysql_result($result,$i,"first"); $last=mysql_result($result,$i,"last"); $phone=mysql_result($result,$i,"phone"); $mobile=mysql_result($result,$i,"mobile"); $fax=mysql_result($result,$i,"fax"); $email=mysql_result($result,$i,"email"); $web=mysql_result($result,$i,"web"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><? echo "$first $last"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$phone"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$mobile"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$fax"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><a href="mailto:<? echo "$email"; ?>">E-mail</a></font></td> <td><font face="Arial, Helvetica, sans-serif"><a href="<? echo "$web"; ?>">Website</a></font></td> </tr> <? ++$i; } echo "</table>"; ?> It displays the table of information. I want to add another column for the option to modify/delete the row of information from the mysql database? Any ideas... Im stuck!!! :'( Thanks all ! Quote Link to comment Share on other sites More sharing options...
msaz87 Posted July 6, 2010 Share Posted July 6, 2010 You have to use the UPDATE and DELETE functions in MySQL... It all just depends on how you want to do it... if you do a checkbox for each one you want to delete, you'd need to post it to whatever page executes the delete script, where you'd do a foreach, check for the ID of the row you want to delete and then delete it... For the update, if you want to have an input box in the table, you could do that, then include the ID of the row in the name of the form field and do the same thing with the array posting to the script that'll update it. Quote Link to comment Share on other sites More sharing options...
myrddinwylt Posted July 6, 2010 Share Posted July 6, 2010 msaz87 is correct. To elaborate a bit, in your MySQL database, create a unique index column which is auto-incremented of type integer. You can then have that as the checkbox id on the html form when you retrieve the records. From there, it's a simple matter of having buttons that post to a page <input type=submit name=delete> <input type=submit name=update> Then on the post page switch ($_POST['submit']) { case "delete": // do delete stuff here break; case "update": // do update stuff here break; } I presently don't recall how to loop through checkboxes that have been posted, but I am sure that information is pretty easy to find if you search the site. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.