MySQL taking variable from a 'while' and using it to update
Posted: Mon Jan 12, 2009 10:15 pm
I would like to run the while and take the 'number' field to correlate with the points in that row of the table to UPDATE the database with the corresponding record.
Thanks for any help!
Code: Select all
<?php
require_once 'dblogin.php';
$result = mysql_query("SELECT * FROM drivers");
if (!isset($_POST['submit'])) {
echo "<table class=\"sortable\" align='center' preserve_style=\"cell\" border='0' width='100%'>
<tr bgcolor=\"fff978\">
<th>Car:</th>
<th>Driver:</th>
<th>Points:</th>
</tr><form action\"" . $_SERVER['PHP_SELF'] . "\" method=\"post\">";
$color1=1;
while($row = mysql_fetch_array($result))
{
if ($color==1){
//Change color of rows
echo "<tr bgcolor=\"ffee55\">";
echo "<td align=\"center\">" . '#' . $row['number'] . "</td>";
echo "<td>" . $row['first_name'] . ' ' . $row['last_name'] . "</td>";
echo "<td align=\"center\">". $row['points'] . "</td>";
echo "<td><input type=\"text\" name= \"" . $row['number'] . "\" size=\"3\" maxlength=\"3\"/></td>";
echo "</tr>";
$color=2;
}
else {
echo "<tr bgcolor=\"cccccc\">";
echo "<td align=\"center\">" . '#' . $row['number'] . "</td>";
echo "<td>" . $row['first_name'] . ' ' . $row['last_name'] . "</td>";
echo "<td align=\"center\">" . $row['points'] . "</td>";
echo "<td><input type=\"text\" name= \"" . $row['number'] . "\" size=\"3\" maxlength=\"3\"/></td>";
echo "</tr>";
$color=1;
}
}
echo "</table> <input type=\"submit\" name=\"submit\" value=\"\Submit\"/></form>";
}
?>