Jump to content

Linking & updating a table cell


BrianM

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/102862-linking-updating-a-table-cell/
Share on other sites

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.

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.