Here are a couple of data type in mySQL:

// YYYY-MM-DD HH:MM:SS
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
status VARCHAR(1),
dateModify TIMESTAMP,
dateCreate TIMESTAMP,
solution TEXT

Here is the code to show the query from mySQL:

<?php
mysql_select_db("databaseName") or die(mysql_error());
global $dateChoose;

$result = mysql_query("SELECT * FROM databaseName WHERE dateCreate >= '$dateChoose' ") 
or die(mysql_error());

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

		echo '<form name="update_form" action="<?php echo $PHP_SELF; ?>" method="post" align="right">';
		echo '<table>';

		echo '<tr>';
		echo '	<td align="right">Modified:</td>';
		echo "	<td><input disabled type=\"text\" name=\"DateModify\" size=\"20\" value=\"{$row['dateModify']}\"></td>";
		echo '</tr>';

		echo '<tr>';
		echo '	<td align="right">Status:</td>';
		echo "	<td><input type=\"text\" name=\"Status\" size=\"1\" value=\"{$row['status']}\"></td>";

		echo '<tr>';
		echo '	<td align="right">Solution:</td>';
		echo "	<td><textarea name=\"Solution\" rows=\"3\" cols=\"40\">{$row['solution']}</textarea>";
		echo '	</td>';
		echo '</tr>';

		echo '<tr>';
		echo '	<td colspan="2" align="center"><input type="submit" value="UPDATE" name="update_form">';
		echo '</tr>';

		echo '</table>';
		echo '</form><br>';	
} //end while
?>



<?php

if (isset($_POST['update_form'])) {
    //update what ever is input such as STATUS Solution 
    //dateModify is 
} 

?>

That code above will output out a nice form with data from mySQL.
NOW I want to update what ever the user input back on form such as SOLUTION, STATUS, etc.. when they click UPDATE.
It would be nice to update all at once of all the inputs from the while loop output.

How would I do that using mySQL UPDATE, SET.

My problem is that my query in a while loop with different data output.

Maybe I set which ID can be update later?

An easy of updating from a tutorial:

<?php
// Connect to MySQL
// Get Sandy's record from the "example" table
$result = mysql_query("UPDATE example SET age='22' WHERE age='21'") 
or die(mysql_error()); 

$result = mysql_query("SELECT * FROM example WHERE age='22'") 
or die(mysql_error()); 

// get the first (and hopefully only) entry from the result
$row = mysql_fetch_array( $result ); echo $row['name']." - ".$row['age']. "<br />";
?> 

    Hello,

    The way you run your WHILE loop, you will have a page with n forms inside, where n is the number of rows returned by your query.

    This is not a problem in itself, but you have to identify the records you want to change, so you need a unique identifier (your ID-Field) for each row. You have to add this one as a hidden field (or a read-only-field). In this case, you will only update the row related to the form of which you clicked the submit-button. (update ... where id = $id)

    If you want to update ALL your records, you first need to put your FORM tags outside the while loop. Then, you need to do really weird things to perform an update in a loop:
    As normally your form fields would have repetitive names, you either have to create names by appending the ID to each name, or to to submit the data as arrays.
    Additionally, if you want to update only those that are really changed, you need to identify the changed recors (for example by some JavaScript that sets a hidden field value when you change some field).

    I did this array thing some years ago, and I don't know if I could quickly find back the details of what I did.

    This is a quick-and-dirty reply, I did not do any testing or in-depth studies, so I hope that I did correctely understand what you want to do, and that my reply could help.

    Greetings,

    JJ Mouris

      Write a Reply...