Send list item to top

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thirteen
Forum Newbie
Posts: 4
Joined: Tue Apr 13, 2010 7:44 am

Send list item to top

Post by thirteen »

I have the following PHP Code which queries a database and generates a list of 4 items.

Code: Select all

echo'<a href="index.php?id='.$id.'&p='.$row["id"].'"><li style="width:207px; background-color:#bcbec0; color:#ffffff; border:0px; font-weight:bold;" class="mainli">'.$row["pagetitle"].'</li></a>';
					$sql2 = "Select * from $table where parent = $row[id] and published = 1 order by menuindex asc";
It works fine and as needed. What I need now is that when I click on a certain item, it moves to the top of the list and the rest remain as they are.

For example it generates:

Nokia
Samsung
Siemens
Motorola

When I lick on Siemens, the list is displayed as follows:

Siemens
Nokia
Samsung
Motorola
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Send list item to top

Post by omniuni »

Unless you want to add javascript, make each item a link to the same page but including movetotop=32 where the number is the ID of your entry in the DB. Fetch the entry, display it at the top, and then remove it from the rest of the results.
thirteen
Forum Newbie
Posts: 4
Joined: Tue Apr 13, 2010 7:44 am

Re: Send list item to top

Post by thirteen »

Can you show demo example or code please?
Post Reply