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.