komquat Posted July 11, 2006 Share Posted July 11, 2006 I am having a problem when updating a table. I am calling multiple rows and adding data to it, but mysql only handles 1 row updates at a time, how can I use php to update all the rows at once.Thanks for the helpCurrent Code:[code=php:0]<?//Start Sessionsession_start();//Validate Userif ($_SESSION[valid] != "yes") { header("Location: http://www.andybourdeau.com/nascar/"); exit;}include("include/connection.php");$p_name = 'n_';$p_name .= $_POST[tag];$driver_name = 'd_';$driver_name .= $_POST[tag];$driver_name_1 = 'd_';$driver_name_1 .= $_POST[tag];$points = 'p_';$points .= $_POST[tag];// Query$sql_drivers = " SELECT fantasy_id, Week, $driver_name, $points FROM nascar_second ORDER BY fantasy_id ";$qry_edit_drivers = mysql_query($sql_drivers, $connection) or die ("Could not Execute query."); //Create Form Block $display_block = " <form method='post' action='admin_show_update_driver.php'> <table border='0'> <tr> <th>Week</th> <th>Driver</th> <th>Points</th> </tr>"; while ($drivers = mysql_fetch_array($qry_edit_drivers)) { $fantasy_id = $drivers[fantasy_id]; $week = $drivers[Week]; $d_name = $drivers[$driver_name]; $points = $info[$points];$display_block .= " <tr> <td>$week</td> <td><input type='text' name='d_name' value='$d_name' size='30'> <input type='hidden' name='fantasy_id' value='$fantasy_id'></td> <input type='hidden' name='driver_name_1' value='$driver_name_1'></td> <td><input type='text' name='points' value='$points' size='3'></td> </tr>"; } $display_block .= " </table> <br> <input type='submit' name='submit' value='Edit Driver Info'> </form> <br> "; echo $display_block;?>[/code]The above is the code to generate the current selections and I am able to make changes here.the next code is where the update will take place, but can not get it to work. Any help is greatly appreciated.[code=php:0]<?//Session Startingsession_start();if ($_SESSION[valid] != "yes") { header("Location:http://www.andybourdeau.com/"); exit;}include("include/connection.php");// Query$sql = " UPDATE nascar_second SET $_POST[driver_name_1] = '$_POST[d_name]' WHERE fantasy_id = '$_POST[fantasy_id]' ";$result = mysql_query($sql, $connection) or die ("Could not Execute Update query. Reason: ".mysql_error()); $display_block = " Completed";echo $display_block;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14331-updating-a-table-problems/ Share on other sites More sharing options...
ShogunWarrior Posted July 11, 2006 Share Posted July 11, 2006 You can loop through them and [b]mysql_query[/b] for each one. Quote Link to comment https://forums.phpfreaks.com/topic/14331-updating-a-table-problems/#findComment-56506 Share on other sites More sharing options...
komquat Posted July 11, 2006 Author Share Posted July 11, 2006 I have no idea how to start, the variables are only recording the last value in the original Loop. I can not get it to bring all values from the first page to the second. Quote Link to comment https://forums.phpfreaks.com/topic/14331-updating-a-table-problems/#findComment-56527 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.