473,471 Members | 2,613 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

More CMS help

Jon
All,

I'm building a CMS, and have run into another problem that I'm not sure
which direction to take on it. Basically, I allow users to add pages, and
allow them to hide/unhide links (sub-navigation) on any page they wish. The
problem now is in the link order. I want them to be able to choose the link
order, and am not sure of the best way to handle this.

I have considered up and down arrows, however I'm not really sure of the
code I'll need to have them query the DB based on that (would I simply
subtract or add one to the linkOrder to the DB?). So, we have also discussed
the use of a drop-down list with a list of numbers showing the current order
(from the DB) that each link is in, along with numbers to change the order
by clicking a down arrow and submitting a form.

My question is mainly - which method would be best? What would the code, or
even the algorithm look like here? The select box code is looking ugly as
hell because I want to echo all of this while I'm echoing the actual links,
and the up/down arrow choices seems confusing as far as the algorithm to me.
Here's the code block I'm using to echo values from the DB as links on the
CMS:

<?php
//start a table
echo "<table width=\"150\"><tr><td></td></tr>";

//call the getLinks function (from a displayClass I have built)
$links = $displayData->getLinks($pageID, $contentID, $data);

//start looping through the records
while($rows=mysql_fetch_array($links)){

//echo links in table cells along with a hide link to have a link
NOT show up on the actual site
echo "<tr><td><a
href=index.php?pageID=".$pageID."&contentID=".$row s['cContentID'].">".$rows['cLinkDisplay']."</a></td><td><a
href=\"index.php?hideLink=".$rows['cContentID']."&contentID=$contentID&pageID=$pageID\">Hide</a></td></tr>";

}

echo "</table>";

?>

Thanks for any help
Jan 20 '06 #1
5 1438
This is how I normally achieve a sortable list:

You should start by setting up a SortOrder (int) column. Each new
record that get's added should cause that # to increment. If this is
going to be a multi-user system or something you should increment it
based on that UserID (so there aren't gaps in the number). Then when
you want to move up simply do:

function MoveUp($id,$replaceID)
{
UPDATE table SET SortOrder=(SortOrder-1) WHERE ID=$id
UPDATE table SET SortOrder=(SortOrder+1) WHERE ID=$replaceID
}

move down would be similar

function MoveDown($id,$replaceID)
{
UPDATE table SET SortOrder=(SortOrder+1) WHERE ID=$id
UPDATE table SET SortOrder=(SortOrder-1) WHERE ID=$replaceID
}

And of course on your select you would ORDER BY SortOrder. There are
several ways you can accomplish this task, this is just the way I do
it. I don't know if this is necessarily the best way, but as long as
your script doesn't leave gaps in the SortOrder # you'll be fine.

Jan 20 '06 #2
Jon
Ok, I've added a linkOrder ID into the DB, and have my up/down arrows
passing order=up and order=down now - My problem now is not incrementing or
decrementing the current id chosen, it's finding the OTHER IDs that will be
affected. Do I literally decrement every orderID for the current pageID? If
the pageIDs are scattered, I really will not know at all what the current ID
is save what came from the DB.

"Adam Plocher" <ap******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
This is how I normally achieve a sortable list:

You should start by setting up a SortOrder (int) column. Each new
record that get's added should cause that # to increment. If this is
going to be a multi-user system or something you should increment it
based on that UserID (so there aren't gaps in the number). Then when
you want to move up simply do:

function MoveUp($id,$replaceID)
{
UPDATE table SET SortOrder=(SortOrder-1) WHERE ID=$id
UPDATE table SET SortOrder=(SortOrder+1) WHERE ID=$replaceID
}

move down would be similar

function MoveDown($id,$replaceID)
{
UPDATE table SET SortOrder=(SortOrder+1) WHERE ID=$id
UPDATE table SET SortOrder=(SortOrder-1) WHERE ID=$replaceID
}

And of course on your select you would ORDER BY SortOrder. There are
several ways you can accomplish this task, this is just the way I do
it. I don't know if this is necessarily the best way, but as long as
your script doesn't leave gaps in the SortOrder # you'll be fine.

Jan 20 '06 #3
Does this fix the problem? It will attempt to find the "replaceID"
automatically. You shouldn't need to shift every item, just the item
before or after the item you want to move.

function MoveUp($id)
{
$query = "SELECT ID FROM table WHERE SortOrder=(SortOrder+1)";
$ret = mysql_query($query);
if (mysql_num_rows($ret) == 1)
{
// if 0 rows returned, don't change the sortorder
list($replaceID) = mysql_fetch_row($ret);

$query = "UPDATE table SET SortOrder=(SortOrder-1) WHERE ID=$id"
mysql_query($query);

$query = "UPDATE table SET SortOrder=(SortOrder+1) WHERE ID=$replaceID"
mysql_query($query);
}
}

Jan 20 '06 #4
Jon
I don't understand the query here - If I'm selecting WHERE
SortOrder=(SortOrder+1) - I don't know what sortOrder is. Do I have to pass
the current sortOrder ID within the query string?

"Adam Plocher" <ap******@gmail.com> wrote in message
news:11********************@g14g2000cwa.googlegrou ps.com...
Does this fix the problem? It will attempt to find the "replaceID"
automatically. You shouldn't need to shift every item, just the item
before or after the item you want to move.

function MoveUp($id)
{
$query = "SELECT ID FROM table WHERE SortOrder=(SortOrder+1)";
$ret = mysql_query($query);
if (mysql_num_rows($ret) == 1)
{
// if 0 rows returned, don't change the sortorder
list($replaceID) = mysql_fetch_row($ret);

$query = "UPDATE table SET SortOrder=(SortOrder-1) WHERE ID=$id"
mysql_query($query);

$query = "UPDATE table SET SortOrder=(SortOrder+1) WHERE ID=$replaceID"
mysql_query($query);
}
}

Jan 20 '06 #5
oops, you're absolutely right, I don't know what I was thinking. How
about something like this

$query = "SELECT ID FROM table WHERE SortOrder=((SELECT SortOrder FROM
table WHERE ID=$id) + 1)";

I don't have any of my PHP or MySQL in front of me, so I'm not testing
this stuff.

Jan 20 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
4
by: Shufen | last post by:
Hi, I'm a newbie that just started to learn python, html and etc. I have some questions to ask and hope that someone can help me on. I'm trying to code a python script (with HTML) to get...
0
by: Tony Lavinio | last post by:
Dear Stylus Studio Friends, The new year is scarcely one month old, but we already have lots to report! For starters, there's Stylus Studio 6 Release 2. The latest release of Stylus Studio...
1
by: GB | last post by:
For various connectivity reasons to my employer's network, I frequently find myself using the telnet-based DB2 client for Sun. Unfortunately, on this client: - The return key submits an SQL...
8
by: Elliot M. Rodriguez | last post by:
I am having a heckuva time debugging this, or determining why my page is behaving this way. I have a search form, that when completed, returns a datagrid. When the user selects a row (normal...
14
by: multiformity | last post by:
So I have been working on an opensource project for a while, and decided to really try to make it look better after focusing on the functionality most of this time. Up to now, I have simply used a...
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
10
by: p3t3r | last post by:
I have a treeview sourced from a SiteMap. I want to use 2 different CSS styles for the root level nodes. The topmost root node should not have a top border, all the other root nodes should have a...
5
by: Hexman | last post by:
I've come up with an error which the solution eludes me. I get the error: >An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in HRTest.exe > >Additional...
15
by: sparks | last post by:
We get more and more data done in excel and then they want it imported into access. The data is just stupid....values of 1 to 5 we get a lot of 0's ok that alright but 1-jan ? we get colums...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.