[SOLVED] Move Up and Move Down mysql results....
Posted: Wed Sep 08, 2004 5:34 am
Hi there!
I'm setting up a script that allows user to add links which are saved in a MySQL Database. First of all, this is what the database looks like:
Now what I want it to do is allow the user to move the place up or down a number so that when the script displays the results on the page, it will put the links in the correct order. For example, I could "switch" the place numbered 03 up to the place numbered 02.
This works similar to the phpBB admin script which allows you to move forums and categories up and down...
At the moment I've go this code below. It works if it finds a number one place less then the first number but not if you don't have a place numbered one less then the first one:
Basically what it's supposed to do is check if the number below it exisits.
E.g: If $place is 03, it needs to check if 02 exisits in the database. And if it does exisit, it will change the place numbered 03 to 02 and the place number 02 to 03 in the database.
And if a place below it does not exisit in the database, it needs to search the number below the one it last searched.
E.g: If $place is 03 it needs to check if 02 exisits in the database. If 02 does not exisit in the database, it needs to check if 01 exists. If 01 exisits in the database, it will change the place numbered 03 to 01 and the place number 01 to 03 in the database.
Anyone have and ideas why this is working.
Hopefully you understand... If not please let me know.
I'm setting up a script that allows user to add links which are saved in a MySQL Database. First of all, this is what the database looks like:
Code: Select all
place | title | url
01 | Jig Heads | jig_heads.php
02 | Soft Plastics |soft_plastics.php
03 | Wire Bait | wire_baits.php
04 | Metal Lures | metal_lures.phpThis works similar to the phpBB admin script which allows you to move forums and categories up and down...
Code: Select all
place | title | url
01 | Jig Heads | jig_heads.php
03 | Soft Plastics |soft_plastics.php
02 | Wire Bait | wire_baits.php
04 | Metal Lures | metal_lures.phpCode: Select all
<?php
if ($place == "01") {
echo msg("Cannot move up! <a href=index.php?file=filesfolders&mode=nav>Back to Modifying Side Navigation Links</a>");
} else {
function fix_num($num) {
if ($num < "10") {
$num = "0".$num;
}
return $num;
}
function check_before($num) {
global $tbl_name;
$check_num = mysql_fetch_array(mysql_query("select place from {$tbl_name}nav where place = $num - 1"));
if ($check_num[place] == "") {
$next_num = $num - 1;
$next_num = fix_num($next_num);
check_before($next_num);
} else {
return $check_num[place];
}
} // end check before
$number = check_before($place);
echo $number; // this should be the first page number below $place
?>E.g: If $place is 03, it needs to check if 02 exisits in the database. And if it does exisit, it will change the place numbered 03 to 02 and the place number 02 to 03 in the database.
And if a place below it does not exisit in the database, it needs to search the number below the one it last searched.
E.g: If $place is 03 it needs to check if 02 exisits in the database. If 02 does not exisit in the database, it needs to check if 01 exists. If 01 exisits in the database, it will change the place numbered 03 to 01 and the place number 01 to 03 in the database.
Anyone have and ideas why this is working.
Hopefully you understand... If not please let me know.