Reply
Re-Order of Records issue MYSQL PHP
Old 05-11-2008, 12:36 AM Re-Order of Records issue MYSQL PHP
Novice Talker

Posts: 12
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);


feelice is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 05-11-2008, 03:08 AM Re: Re-Order of Records issue MYSQL PHP
Junior Talker

Posts: 3
Quote:
Originally Posted by feelice View Post
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...
It looks like that the bottom 6 records have the same order id. Go to your database and verify their order id.
__________________
PHP, Apache, MySQL
mwasif is offline
Reply With Quote
View Public Profile Visit mwasif's homepage!
 
Old 05-11-2008, 04:41 PM Re: Re-Order of Records issue MYSQL PHP
Novice Talker

Posts: 14
Quote:
Originally Posted by mwasif View Post
It looks like that the bottom 6 records have the same order id. Go to your database and verify their order id.
thats what i was thinkin, from scanning over the code nothing major sticks out, though i could have missed something =)
localhost8080 is offline
Reply With Quote
View Public Profile
 
Old 05-11-2008, 05:58 PM Re: Re-Order of Records issue MYSQL PHP
joder's Avatar
Flipotron

Posts: 6,347
Name: James
Location: In the ocean.
How are you coming up with orderid's? Isn't it the primary key and why wouldn't it be autoincremented?
joder is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Re-Order of Records issue MYSQL PHP
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.19596 seconds with 13 queries