Hi,

I my admin area, where the administrator can create a new page, it is also possible to decide the position of the link.

It is a menu in the left side of the screen, one link on top of the other, very simple nav.

I have a dropdown list in the admin area, where the admin can (After filling out all the form fields) decide where the link shoul be positioned.

After choosing a position from the dropdown list, the information gets sent to the database, but my problem is this:

If admin changes a link from lets say: position 4, to position 2 - Then the link that had position 2, stays with the same position. So I end up having to links positioned with the same number. I am gettting the links from the database, after position ASC.

I want to update the rest of the table so no links can have the same position.

I am only writing the mysql query, as i think it would be here i need to make some adjustments.

(I need to update it something like this: lets say I have 4 links in my vertical menu. They have a different number (position: 1,2,3,4 - from the databse), and after I change a position of a link, say link positiones as no. 4, to position no.2, then I need the links positoned with value =>2, to ++1...I just dont know how I can write this correctly.)

My processing code for creating a new page looks like this:

<?php
// Add the info into the database table
 
$query = mysqli_query($myConnection, "INSERT INTO pages (pagetitle, description, keywords, linklabel, position, heading, pagebody, lastmodified) 
        VALUES('$pagetitle','$description', '$keywords', '$linklabel', '$position', '$heading', '$pagebody',now())") or die (mysqli_error($myConnection));
 
// IS IT HERE THAT I SHOULD WRITE ANOTHER QUERY TO UPDATE THE POSITION OF THE OTHER LINKS IN THE DATABSE, AND HOW COULD THIS BE DONE...??
 
echo '<div align="center">Operation Completed Successfully! Head back to the admin home page, or the main website to see your changes!<br /><br /><a href="login/admin.php">Click Here For Admin home!</a> 
<br /><br /><a href="../index.php" >Or head back to view the live website!</a></div>';
exit();
?>

Help will be appreciated,

Klemme

You have to do it in several steps:
1) Check if there is a link with position 2 in the database.
2) If it is, UPDATE pages SET position=position+1 WHERE position >= 2 3) Now do your INSERT query

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.