473,472 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dynamic MySQL Nav Menu sorting

Hello again,

I have this dynamic menu and I want to change the order of the menu items...
I added a column in the database wich has an integer value for ordering the
menuitems.
But the only way is by hardcoding them into the database.

I would like a way to sort them with drag-and-drop or with up/down arrows.

Do you think that except PHP & MYsql I will need Javascript as well ?
Any ideas how to do that ?

Thanks a lot,
Angelos.
Nov 22 '05 #1
3 4928
for a real drag-and-drop you'll need javascript.

using arrows to move an item up or down can be done with php. the
drawback here would be that every click on an arrow will cause a trip
back to the server to recreate the menu in the new order.

wether to use a javascript or php approach depends on a lot of factors,
to name a few:

- if the sorting is a crucial functionality of your site, don't use
javascript (people might have it disabled or not even visiting with a
browser)
- if the new order shall be stored for a certain user, you'll need php
anyway
- if speed is a factor, javascript maybe better

i personally would probably use php and not mess around with
javascript.

micha

Nov 22 '05 #2
In article <dl**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com>,
"Angelos" <an*****@redcatmedia.net> wrote:
Hello again,

I have this dynamic menu and I want to change the order of the menu items...
I added a column in the database wich has an integer value for ordering the
menuitems.
But the only way is by hardcoding them into the database.

I would like a way to sort them with drag-and-drop or with up/down arrows.

Do you think that except PHP & MYsql I will need Javascript as well ?
Any ideas how to do that ?


I do this all the time.

In pseudo code:

$position=0;
foreach ($menu as $m){
$position++;
$uplink = "admin.php?move=$m[id]&to=" ($position-1);
$downlink = "admin.php?move=$m[id]&to=" ($position+1);

print "(uplink icon) (downlink icon) row data....<br />";
}
Then you update the sortorder field when either link is clicked. Remember to
update the field that it is moved TO so it is moved down/up respectively.

Of course, if the row is the first or the last, you shouldn't have either a
uplink or downlink.

Plus, if you have a hierarchical menu (like I do), you need to keep track of
the position number relative to the current hierarchy leve and send that along
with the query (i.e. move=12&to=3&mother=23)
--
Sandman[.net]
Nov 22 '05 #3
I do this all the time.

In pseudo code:

$position=0;
foreach ($menu as $m){
$position++;
$uplink = "admin.php?move=$m[id]&to=" ($position-1);
$downlink = "admin.php?move=$m[id]&to=" ($position+1);

print "(uplink icon) (downlink icon) row data....<br />";
}
Then you update the sortorder field when either link is clicked. Remember
to
update the field that it is moved TO so it is moved down/up respectively.

Of course, if the row is the first or the last, you shouldn't have either
a
uplink or downlink.

Plus, if you have a hierarchical menu (like I do), you need to keep track
of
the position number relative to the current hierarchy leve and send that
along
with the query (i.e. move=12&to=3&mother=23)

Now we are talking....
Nice One Sandman. ... I'll try that today ;-)
Nov 22 '05 #4

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

Similar topics

3
by: Angelos | last post by:
Hello there, I am trying to write a script that will create dynamically a menu from MySQL database. The database table is a product categories table and it has the folowing filed: category_id,...
12
by: CJM | last post by:
How can I dynamically sort the results from a Stored Procedure? Or more importantly, what is the fastest and most efficient way? I know I can do the sorting within the recordset in ASP, but AFAIK...
1
by: Angelos | last post by:
Hello again, I have this dynamic menu and I want to change the order of the menu items... I added a column in the database wich has an integer value for ordering the menuitems. But the only way...
19
by: mart2006 | last post by:
I've created a dynamic drop down menu that populates itself with data from a MySQL table. What I would like to do is create a non dynamic drop down menu that alters what is shown in the dynamic menu....
10
by: jflash | last post by:
Hello all, I feel dumb having to ask this question in the first place, but I just can not figure it out. I am wanting to set my site up using dynamic urls (I'm assuming that's what they're...
3
by: drblitzkrieg | last post by:
Hi, I have a page with 2 drop-down menus. The task is, when you select 1 menu, your selection then changes the options available in the other. This data happens to be drawn from a mysql database,...
3
by: jaddi1 | last post by:
Hi, I am trying to make a multi-level drop-down menu similar to what is seen here: http://www.cssplay.co.uk/menus/simple_vertical.html. My problem is that some of the menu will be populated from...
10
by: mart2006 | last post by:
Hi, I'm fairly new to PHP and I've created a dynamic drop down menu that populates itself with data from a MySQL table. What I would like to do is create a non dynamic drop down menu that alters...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
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.