BrianM Posted April 25, 2008 Share Posted April 25, 2008 I got as far as finding an example online that shows how to set the entire table cell as a link and not just the contents that are contained inside. So my question is, using the onClick command(i guess it's some sort of javascript thing, never have looked into javascripting), can anyone show me an example of how to (and after clicking the cell, of course) turn the cell into a text box where you can edit the cell content and click a submit button under or around the table (wherever your preference to place it) and it will update the information in the database table for that column and rows input. Quote Link to comment Share on other sites More sharing options...
BrianM Posted April 25, 2008 Author Share Posted April 25, 2008 Bump. Quote Link to comment Share on other sites More sharing options...
TEENFRONT Posted April 25, 2008 Share Posted April 25, 2008 do a lil search for inline edit php. It wikll use php and ajax to acomplish what your after if iv understood correctly. http://www.yvoschaap.com/index.php/weblog/ajax_inline_instant_update_text_20 is the first tutorail google gave me when i search. Quote Link to comment Share on other sites More sharing options...
BrianM Posted April 25, 2008 Author Share Posted April 25, 2008 Better yet, does anyone know of a simple way to edit the contents of a table cell linked to a table in a database that's being displayed in a web page? Quote Link to comment Share on other sites More sharing options...
BrianM Posted April 26, 2008 Author Share Posted April 26, 2008 Bump. Quote Link to comment Share on other sites More sharing options...
Fadion Posted April 26, 2008 Share Posted April 26, 2008 It would be better to use ajax & php in this case, but as this is a php forum and im not very good with ajax, ill give u a pure php solution. <?php if(isset($_POST['text'])){ $text = $_POST['text']; $resultsUpdate = mysql_query("UPDATE table SET text='$text' WHERE id=4"); } $resultsShow = mysql_query("SELECT id, text FROM table WHERE id=4") or die(); $valuesShow = mysql_fetch_array($resultsShow); ?> <table> <tr> <td> <?php if($_GET['action'] != 'edit'){ echo $valuesShow['text'] . '<br /><br />'; echo "<a href='mypage.php?action=edit'>Click here to edit the text</a>"; } else{ ?> <form name="formEdit" method="post" action="mypage.php"> <textarea name="text"><?php echo $valuesShow['text']; ?></textarea> <input type="submit" name="Submit" value="Submit" /> </form> <?php } ?> </td> </tr> </table> This is the way its done. When the edit link is clicked, an url variable is passed which tells the script that it should show the edit form. When submit is clicked, the db is updated. Surely this is the simplest scenario just to illustrate, so the id=4 i used should be dynamic and if u have multiple rows of data the script needs further modifications. Hope this helped. Quote Link to comment Share on other sites More sharing options...
BrianM Posted April 26, 2008 Author Share Posted April 26, 2008 I can definitely see this working. Although, yes, I will have to alter tables and what not. I'll report back and let you know how it goes. Quote Link to comment Share on other sites More sharing options...
BrianM Posted May 2, 2008 Author Share Posted May 2, 2008 Well, I was on a little vacation for a few days, back now. I tried the code and my page doesn't display anything when I add in what you gave me to use :| arg. I get nothing with error_reporting(E_ALL); ... so can anyone give me a hand and point me in the right direction, please? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>MPS - Send Client Data</title> </head> <?php $mysql_hostname = "localhost"; $mysql_username = "brian"; $mysql_password = ""; $mysql_database = "mps"; $mysql_connect = mysql_connect("$mysql_hostname", "$mysql_username", "$mysql_password") or die(mysql_error()); mysql_select_db("$mysql_database") or die(mysql_error()); mysql_select_db("$mysql_database"); $result = mysql_query("SELECT * FROM `08-12345-1`"); if(isset($_POST['text'])) { $text = $_POST['text']; $resultsUpdate = mysql_query("UPDATE table SET text='$text' WHERE id=4"); } $resultsShow = mysql_query("SELECT id, text FROM table WHERE id=4") or die(); $valuesShow = mysql_fetch_array($resultsShow); ?> <table> <tr> <td> <?php if($_GET['action'] != 'edit') { echo $valuesShow['text'] . '<br /><br />'; echo "a href='http://www.game-zero.org/mps/projects/project_08-12345-1.php?action=edit'>Click here to edit the text</a>"; } else { ?> <form name="formEdit" method="post" action="http://www.game-zero.org/mps/projects/project_08-12345-1.php"> <textarea name="text"><?php echo $valuesShow['text']; ?></textarea> <input type="submit" name="Submit" value="Submit" /> </form> <?php } ?> </td> </tr> </table> <?php echo "<table border=1> <tr> <th> Permit Process </th> <th> Req </th> <th> Submittal Date </th> <th> Comments Received Date </th> <th> Resubmit Date </th> <th> Comments Received Date </th> <th> Resubmit Date </th> <th> Comments Received Date </th> <th> Resubmit Date </th> <th> Comments Received Date </th> <th> Resubmit Date </th> <th> Approval Date </th> <th> Permit Number </th> <th> CoC Req Date </th> <th> CoC Submittal Date </th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td><center><b>" . $row['PermitProcess'] . "</b></center></td>"; echo "<td><center><b>" . $row['Req'] . "</b></center></td>"; echo "<td><center><b>" . $row['SubmittalDate'] . "</b></center></td>"; echo "<td><center><b>" . $row['CommentsReceivedDate1'] . "</b></center></td>"; echo "<td><center><b>" . $row['ResubmitDate1'] . "</b></center></td>"; echo "<td><center><b>" . $row['CommentsReceivedDate2'] . "</b></center></td>"; echo "<td><center><b>" . $row['ResubmitDate2'] . "</b></center></td>"; echo "<td><center><b>" . $row['CommentsReceivedDate3'] . "</b></center></td>"; echo "<td><center><b>" . $row['ResubmitDate3'] . "</b></center></td>"; echo "<td><center><b>" . $row['CommentsReceivedDate4'] . "</b></center></td>"; echo "<td><center><b>" . $row['ResubmitDate4'] . "</b></center></td>"; echo "<td><center><b>" . $row['ApprovalDate'] . "</b></center></td>"; echo "<td><center><b>" . $row['PermitNumber'] . "</b></center></td>"; echo "<td><center><b>" . $row['CoCReqDate'] . "</b></center></td>"; echo "<td><center><b>" . $row['CoCSubmittalDate'] . "</b></center></td>"; echo "</tr>"; } echo "</table> </font>"; mysql_close($mysql_connect); ?> <body> </body> </html> Quote Link to comment Share on other sites More sharing options...
BrianM Posted May 2, 2008 Author Share Posted May 2, 2008 Is there any certain order I should put the code, or a syntax error I made? Quote Link to comment Share on other sites More sharing options...
BrianM Posted May 2, 2008 Author Share Posted May 2, 2008 Any advice? 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.