I have a table that has a cell that is contentEditable
. My problem is that the content is a date, and is it possible that the cell will look like <input type="date">
? So I can only update date if the column has a value and insert if it doesn't.
Here is what I got:
while ($record = mysql_fetch_array($myData)) {
echo"<tr>";
echo "<td><div contenteditable>" . $record['clientID'] . "</div></td>";
echo "<td><div contenteditable>" . $record['date'] . "</div></td>";
echo "<th><a href='test.php'>Update</a> ";
echo"</tr>";
}
Solved it. I didn't use contentEditable
instead I used <input type="date">
. The cell is editable as a date.
Here is what I did:
while ($record = mysql_fetch_array($myData)) {
echo"<tr>";
echo "<td>" . $record['clientID'] . "</td>";
echo "<td> <input type='date' value='". $record['date'] ."'> </td>";
echo "<th><a href='test.php'>Update</a> ";
echo"</tr>";
}
Get $queryResultArray and populate a form:
$queryResultArray = [];
if ($myData) {
while ($record = mysql_fetch_array($myData)) {
$queryResultArray[] = $record;
}
}
<form action="" method="post">
<table>
<?php foreach($queryResultArray as $value) { ?>
<tr>
all other data
<td><input type="date" name="date" value="<?php echo $value['date'];?>"</td>
<td><input type="submit" name="<?php echo $value['clientID'];?>" value="Update"></td>
</tr>
<?php } ?>
</table>
</form>
After the form submit you get the edited row by name = cliendID and you edit the DB for this ID.