Hi all,
I am updating the position og pages, which I get dynimacally from the DB.
It is d possible via the backend, for the admin of the site, to decide which position a page should have, when updating or creating a new page for the site.
I let the admin write the position in a textfield, whch then updates the database, and the positions in that specific row.
BUT, lets say there is only 3 ages under the subject which admin is either editing or creating a new page for. The admin can by mistake enter the position of a page to be lets say, position: 7 - And with less pages for that subject, I will have gaps in the position.
So I want to do the following:
If there is 3 pages, and admin writes a position number, which value is 2 or above, than the actual number of pages - Then I want to make that position number equal to the highest value, and +1, so it is the highest value, but leaving no gaps.
Can I do something like this:
Only showing the relevant bit..
$position = $_POST['position'];
$subjectid = $_POST['subjectid'];
// Here I want to check if the value of $position is 2 or more above the actual values in the DB..
$result = mysqli_query("SELECT * FROM PAGES WHERE subjectid = $subjectid");
$NumberOfRows = mysqli_num_rows($connection, $result);
// Isnt that the way to get the highest value from that specific row??
// HOW CAN I WRITE THIS BELOW????
if($position // is +2> (2 or higher than) $NumberOfRows) {
$position = $NumberOfRows;
// Does this give me ONE value in $position (The highest)?
$query = ($connection, "INSERT INTO pages pagetitle, linklabel, subjectid, position, showing, description, keywords, pagebody) VALUES
('$pagetitle', '$linklabel' '$subjectid', '$position', '$showing', '$description', '$keywords', '$pagebody'");
// And then update the position after this query?
$QueryAdjustPositionOneUp = ($connection, "UPDATE pages SET position = position + 1 WHERE position = $position AND subjectid = $subjectid");
}