loop update set question
Posted: Fri May 14, 2004 9:46 am
hello everybody,
i have an idea, but i'm having problems actually putting the logic together.
What i want to do it sort the results of my database (variable results) and then allot point values (per the noted equation) and then resubmit back up to the databse in the appropriate field (prix_id)
here is the loop to display the form:
-------------------------------------------------------------------------------
<html>
<head>
<title>Update form</title>
</head>
<body>
<?php
$db = mysql_connect("localhost", "...", "...");
mysql_select_db("....",$db);
$run_query = "SELECT * FROM table WHERE sex = 'male' and one_time > 0 order by one_time";
$run_result = mysql_query($run_query);
$numrows = mysql_numrows($run_result);
$i=1;
while($run_row = mysql_fetch_array($run_result)){
echo "<form method=\"post\" action=\"update_one.php\">";
$mydataorder = $run_row[user] + $i;
echo "<input type=\"text\" name=\"order\" value=\"$mydataorder\">";
echo "<input type=\"text\" name=\"first_name\" value=\"$run_row[first_name]\">";
echo "<input type=\"text\" name=\"last_name\" value=\"$run_row[last_name]\">";
echo "<input type=\"text\" name=\"prix_id\" value=\"$run_row[prix_id]\">";
echo "<input type=\"text\" name=\"age\" value=\"$run_row[age]\">";
echo "<input type=\"text\" name=\"one_place\" value=\"$run_row[one_place]\">";
echo "<input type=\"text\" name=\"team\" value=\"$run_row[team]\">";
echo "<input type=\"text\" name=\"one_time\" value=\"$run_row[one_time]\">";
$mydatapoint = ROUND(1000-($mydataorder-1)*(1000/$numrows));
echo "<input type=\"text\" name=\"one_points\" value=\"$mydatapoint\">";
echo "<br>";
$i++;
}
echo "<input type=\"submit\"></form>";
?>
</body>
</html>
---------------------------------------------------------------------------
here is the update page:
-----------------------------------------------------------------------
<html>
<head>
<title>Update form</title>
</head>
<body>
<?php
$db = mysql_connect("localhost", ".....", ".....");
mysql_select_db(".....",$db);
$qry = mysql_query("UPDATE table SET one_points='$one_points' WHERE prix_id='$prix_id'") or die('Error during update query');
if($qry){
echo "Update passed";
}else{
echo "Update failed";
}
?>
</body>
</html>
----------------------------------------------------------
thanks!
-Michael
i have an idea, but i'm having problems actually putting the logic together.
What i want to do it sort the results of my database (variable results) and then allot point values (per the noted equation) and then resubmit back up to the databse in the appropriate field (prix_id)
here is the loop to display the form:
-------------------------------------------------------------------------------
<html>
<head>
<title>Update form</title>
</head>
<body>
<?php
$db = mysql_connect("localhost", "...", "...");
mysql_select_db("....",$db);
$run_query = "SELECT * FROM table WHERE sex = 'male' and one_time > 0 order by one_time";
$run_result = mysql_query($run_query);
$numrows = mysql_numrows($run_result);
$i=1;
while($run_row = mysql_fetch_array($run_result)){
echo "<form method=\"post\" action=\"update_one.php\">";
$mydataorder = $run_row[user] + $i;
echo "<input type=\"text\" name=\"order\" value=\"$mydataorder\">";
echo "<input type=\"text\" name=\"first_name\" value=\"$run_row[first_name]\">";
echo "<input type=\"text\" name=\"last_name\" value=\"$run_row[last_name]\">";
echo "<input type=\"text\" name=\"prix_id\" value=\"$run_row[prix_id]\">";
echo "<input type=\"text\" name=\"age\" value=\"$run_row[age]\">";
echo "<input type=\"text\" name=\"one_place\" value=\"$run_row[one_place]\">";
echo "<input type=\"text\" name=\"team\" value=\"$run_row[team]\">";
echo "<input type=\"text\" name=\"one_time\" value=\"$run_row[one_time]\">";
$mydatapoint = ROUND(1000-($mydataorder-1)*(1000/$numrows));
echo "<input type=\"text\" name=\"one_points\" value=\"$mydatapoint\">";
echo "<br>";
$i++;
}
echo "<input type=\"submit\"></form>";
?>
</body>
</html>
---------------------------------------------------------------------------
here is the update page:
-----------------------------------------------------------------------
<html>
<head>
<title>Update form</title>
</head>
<body>
<?php
$db = mysql_connect("localhost", ".....", ".....");
mysql_select_db(".....",$db);
$qry = mysql_query("UPDATE table SET one_points='$one_points' WHERE prix_id='$prix_id'") or die('Error during update query');
if($qry){
echo "Update passed";
}else{
echo "Update failed";
}
?>
</body>
</html>
----------------------------------------------------------
thanks!
-Michael