ok, i ended up having to do a little off coding to get my cms menu, content and other stuff to insert in the DB properly. i use 'id' and 'display' in the menu table because display is what i sort by, and i give the ability to re-organize the nav for the CMS, so, i felt it was better to have a regular ID and a display id.
so, the problem i was running into was that i was just counting the rows and trying to add 1 to the number of rows returned. not good if you start removing entries from the database because then you would end up with duplicate display id's, and things would start getting messed up.
so, i thought i would share my solution in case anyone else was looking to do something similar.
so, there you have it, now,if i call $display, it will find whatever the highest number is found in the DB, and add 1 to it.
example...
display[]
1
2
5
6
9
15
25
13
14
12
88
55
23
69
32
after sorted, it would look like...
display[]
1
2
5
6
9
12
13
14
15
23
25
32
55
69
88
therefore determining that 88 is the highest number found, and since we add one to it, the $display variable would become 89. now we have a good display id to work with and there should not be any more duplicate display id's messing up the CMS navigation.
hope this is useful to someone else besides me.
so, the problem i was running into was that i was just counting the rows and trying to add 1 to the number of rows returned. not good if you start removing entries from the database because then you would end up with duplicate display id's, and things would start getting messed up.
so, i thought i would share my solution in case anyone else was looking to do something similar.
PHP:
// Get the curent display ID number
$SQL = "SELECT * FROM menu"; // Select the table to query
$result = mysql_query($SQL); // Run a standard query
$numRows = mysql_num_rows($result); // Count the number of rows returned
$posNums = array(); // build an array for the results we are going to return
for ($i = 0; $i < $numRows; $i++) { // loop through the results found starting at the first column
$row = mysql_fetch_row($result); // determine where column in the table that we want to loop through
$pID = $row[1]; // we want the display id, not the regular id, so, we go with row 1
$posNums[$i] = $pID; // store all the array values in the array found in $pID
}
sort($posNums); // Sort the array results with the smallest number first in case results are out of order
$lastID = end($posNums); // find the last number after the array was sorted
$lastID++; // add one more number to the highest number found
$display .= $lastID; // once the new number was created, store it as a variable to be used later
so, there you have it, now,if i call $display, it will find whatever the highest number is found in the DB, and add 1 to it.
example...
display[]
1
2
5
6
9
15
25
13
14
12
88
55
23
69
32
after sorted, it would look like...
display[]
1
2
5
6
9
12
13
14
15
23
25
32
55
69
88
therefore determining that 88 is the highest number found, and since we add one to it, the $display variable would become 89. now we have a good display id to work with and there should not be any more duplicate display id's messing up the CMS navigation.
hope this is useful to someone else besides me.