let me first explain the issue, im kinda new at php so im hoping someone can catch what i am not... I've made a script that re-orders placement of data, basicly every mysql record i have in a table has a order_id (not a reqular id), and data is spit out based on the order_id. THE PROBLEM: i have 25 records in a table, when i go to reorder them the bottom 6 are stuck and wont do anything , but the top 19 will reorder... I hope that makes sense here is the page that does it:
PHP Code:
<?php
$mvdown = $_POST['mvdown'];
$mvup = $_POST['mvup'];
$id = $_POST['Id'];
$order_id = $_POST['order_id'];
// includes
include('config.php');
//include('../functions.php');
$connection = mysql_connect($host, $user, $pass) or die ('Unable to connect!');
mysql_select_db($db) or die ('Unable to select database!');
if ($mvdown ==1)
{
$PrevOrder_id = $order_id-1;
$query = "SELECT Id, order_id FROM industrial WHERE order_id = $PrevOrder_id";
$prevresult = mysql_query($query);
$row = mysql_fetch_object($prevresult);
$ThePrevOrder = $row->order_id;
$ThePrevID = $row->Id;
$query = "SELECT Id, order_id FROM industrial WHERE Id = $id";
$currresult = mysql_query($query);
$row = mysql_fetch_object($currresult);
$TheCurrOrder = $row->order_id;
$TheCurrID = $row->Id;
$query = "UPDATE industrial SET order_id = $TheCurrOrder WHERE Id = $ThePrevID";
$result = mysql_query($query);
$query = "UPDATE industrial SET order_id = $ThePrevOrder WHERE Id = $TheCurrID";
$result = mysql_query($query);
}
//// Move Up
if ($mvup == 1)
{
$NextOrder_id = $order_id+1;
$query = "SELECT Id, order_id FROM industrial WHERE order_id = $NextOrder_id";
$nextresult = mysql_query($query);
$row = mysql_fetch_object($nextresult);
$TheNextOrder = $row->order_id;
$TheNextID = $row->Id;
$query = "SELECT Id, order_id FROM industrial WHERE Id = $id";
$currresult = mysql_query($query);
$row = mysql_fetch_object($currresult);
$TheCurrOrder = $row->order_id;
$TheCurrID = $row->Id;
$query = "UPDATE industrial SET order_id = $TheCurrOrder WHERE Id = $TheNextID";
$result = mysql_query($query);
$query = "UPDATE industrial SET order_id = $TheNextOrder WHERE Id = $TheCurrID";
$result = mysql_query($query);
}
$query = "SELECT MAX(order_id) as MAX_ORDER FROM industrial";
$maxnum = mysql_query($query);
$row = mysql_fetch_object($maxnum);
$themaxorder = $row->MAX_ORDER;
$query = "SELECT MIN(order_id) as MIN_ORDER FROM industrial";
$minnum = mysql_query($query);
$row = mysql_fetch_object($minnum);
$theminorder = $row->MIN_ORDER;
$query = "SELECT * FROM industrial ORDER BY order_id DESC";
$result = mysql_query($query)
or die ("Error in query: $query. " . mysql_error());
// if records present
if (mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_object($result))
{
?>
<img src="../storedimg/industrial/images/<?php echo $row->filename; ?>" width="100" height="75"><br>
<font size="3"><b><?php echo $row->title; ?></b></font>
<?
//if highest order dont display
if ($row->order_id < $themaxorder) {
?>
<form name="orderup" action="order.php" method="post">
<input type="hidden" name="Id" value="<?php echo $row->Id; ?>">
<input type="hidden" name="order_id" value="<?php echo $row->order_id; ?>">
<input type="hidden" name="mvup" value="1">
<input type="image" name="" src="orderup_btn.gif" border="0" />
</form>
<?
} else {
}
//if lowest order dont display
if ($row->order_id > $theminorder) {
?>
<form name="orderdown" action="order.php" method="post">
<input type="hidden" name="Id" value="<?php echo $row->Id; ?>">
<input type="hidden" name="order_id" value="<?php echo $row->order_id; ?>">
<input type="hidden" name="mvdown" value="1">
<input type="image" name="" src="orderdown_btn.gif" border="0" />
</form>
<?
} else {
}
?>
<p><br>
<?php
}
}
// if no records present
// display message
else
{
?>
<font size="-1">No releases currently available</font><p>
<?php
}
// close connection
mysql_close($connection);

|