...

View Full Version : increment record order



angst
06-08-2007, 08:58 PM
Hello!

having issues with this function, mainly the logic behind it I guess.

I've got a very simple CMS, and order the pages to be displayed on the front end with a TinyInt field in the db.



Function SetPageOrder($numSectionID,$numPageOrder){

// Check Page Order and Increment if needed
$result = mysql_query("SELECT Id,PageOrder FROM pages WHERE ParentID = " . $numSectionID );
while ($row = mysql_fetch_array($result)){
If($numPageOrder == $row['PageOrder'] || $numPageOrder < $row['PageOrder']){
mysql_query( "UPDATE PageOrder SET PageOrder = PageOrder + 1 WHERE Id=" . $row['Id'] );
}
}
}


what i'm trying to do here, is if i create a new page and set the page order to 1 for example, I would like all the other pages in that section to bump up a number. I thought this function would work, but no go.

any ideas would be great,

thanks in advance for your time!
-Ken

ess
06-08-2007, 10:36 PM
you will need to select all the records that are equal to 1 and more than 1

for example


SELECT * FROM PAGES WHERE PAGE_ORDER =< 1

then loop through all records and update them accordingly
for example


UPDATE PAGES
SET PAGE_ORDER = $row['PAGE_ORDER'] + 1

Cheers
Ess



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum