I want to be able to change the INT value (display_order) for all the rows in my table via a single form in the admin cp I am coding. This idea along the lines of vB's forum display order.
I've got it all set up and the query is working, its just that my code will only update the record with the highest display number rather than updating all the rows.
The purpose of this if you are wondering is to allow my church to add and edit sections to a given (in this case the Children's Ministry page) page and be able to decide what order the section are displayed.
The database uses four columns: id, title, content, display_order. Like I said before the problem is that it is only updating the row with the highest display_order value rather than all of them. I would like it to update all at once to make it simple for the staff at my church to update things as they need. Any help is greatly appreciated!
See the script: http://www.wildewoodbc.org/temp/children.php
Code
<?
include('global.php');
$title = 'Children\'s Page';
// ################################ ORDER SECTIONS #############################
if ($_REQUEST['do'] == 'modify' OR empty($_REQUEST['do']))
{
print("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<title>" . $sitetitle . " Control Panel - " . $title . "</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />
<link href=\"cpcss.css\" rel=\"stylesheet\" type=\"text/css\" />
<style type=\"text/css\">
<!--
body {
SCROLLBAR-BASE-COLOR: #5075B4;
SCROLLBAR-ARROW-COLOR: #FFFFFF;
}
//-->
</style>
</head>
<body bgcolor=\"#EBF3FE\" leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">
<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td class=\"title\">
<div align=\"right\">" . $title . "</div></td>
</tr>
</table>
<br />
<table width=\"95%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td class=\"navborder\"><table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\">
<tr>
<td class=\"bodycat\">" . $title . "</td>
</tr>
<tr>
<td><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">
<form name=\"updateorder\" id=\"updateorder\" method=\"post\" action=\"children.php?do=updateorder\">
<tr class=\"formmisc\">
<td>Modify Section</td>
<td><div align=\"right\">Change Dislpay Order</div></td>
</tr>");
$query = "SELECT * FROM page_children ORDER BY display_order ASC";
$result = mysql_query($query, $link);
$i = 1 ;
while($row = mysql_fetch_assoc($result)){
$id = $_row['display_order']; // ???? what is thius used for ???
if ($i % 2 == 0) { // so if it is an even rownumber
echo ('<tr class="alt1">');
} else {
echo ('<tr class="alt2">');
}
$i ++ ;
echo ('<td>' . $row['title'] . '</td>');
echo ('<td><div align="right"><input id="id" name="id" type="hidden" value="' . $row['id'] . '" /><input class="fields" id="display_order" name="display_order" type="text" value="' . $row['display_order'] . '" size="5" /></div></td>');
echo ('</tr>');
}
print("<tr>
<td colspan=\"2\" class=\"formmisc\"><div align=\"center\">
<input name=\"Submit\" type=\"submit\" class=\"button\" value=\"Submit\" />
</div></td>
</tr>
</form>
</table></td>
</tr>
</table>
</td>
</tr>
</table></td>
</tr>
</table>");
print($cpfooter);
print("</body>
</html>");
}
// ###################### UPDATE THE ORDER #######################
if ($_GET['do'] == 'updateorder') {
$id = $_POST['id'];
$display_order = $_POST['display_order'];
$query = "UPDATE page_children SET display_order = '$display_order' WHERE id = '$id'";
print($query);
}
?>
(Note: I know I don't have my query set up to update the database, I am printing it so that I can see what info its sending.)