[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

simple link ordering

Posted on 2006-07-01
7
Medium Priority
?
262 Views
Last Modified: 2012-08-14
hi, i have a table links with
id,name,url,lorder

i need a simple up and down function, that will change the lorder, and according that i'll be able to sort them in my admin...
0
Comment
Question by:svsvsv
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 10

Expert Comment

by:sakuya_su
ID: 17025026
lorder is numbers or characters?
0
 
LVL 10

Expert Comment

by:sakuya_su
ID: 17025028
anyway, load all the lorders into an array and use the functipon sort as described in  http://www.php.net/sort
0
 
LVL 11

Expert Comment

by:Joseph Melnick
ID: 17025260
Hello svsvsv,

assuming that you save your data in a database then you can output your links based on your
lorder field.

$query = "select id,name,url,lorder from linktable order by lorder";

Joseph Melnick
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:svsvsv
ID: 17025903
i need a "up","down" buttons to order them up in my db
0
 
LVL 11

Expert Comment

by:Joseph Melnick
ID: 17026695
Hello svsvsv,

your database can order ascending and decending.

$query = "select id,name,url,lorder from linktable order by lorder asc";
OR
$query = "select id,name,url,lorder from linktable order by lorder desc";

ASC or DESC can be passed with an up /down arrow.
list.php?direction=up
list.php?direction=down

example:

<?php
if(array_key_exists('direction',$_GET) and $_GET['direction'] == 'up' )
{
$query = "select id,name,url,lorder from linktable order by lorder asc";
}
elseif(array_key_exists('direction',$_GET) and $_GET['direction'] == 'down' )
{
$query = "select id,name,url,lorder from linktable order by lorder desc";
}
else
{
$query = "select id,name,url,lorder from linktable";
}
?>

If your intention is to use arrow buttons to manage the location of each item in your list than a more ajaxy solution might be in order.

Joseph Melnick
0
 

Author Comment

by:svsvsv
ID: 17027175
yes i was interested in using them as setting the location of each item
0
 
LVL 11

Accepted Solution

by:
Joseph Melnick earned 2000 total points
ID: 17027909
Hello svsvsv,

if you want to reorder a list with lorder = 1,2,3,4,5,6,7,8,9...
and you want to click an arrow button to swap position in the list with the previous and current position OR next and current position. by simply clicking.

url on arrow with a url like the following examples:
// id is the row id, lorder is the links order and
// direction is the position you want that row to move        

....create these dynamically inside your table creation loop replacing 5 and 5 for row id, lorder from your mysql table.

<a href="showdatatable.php?id=5&lorder=5&direction=up" title="up">
<img src="/images/up.gif" alt="up">
</a>
<a href="showdatatable.php?id=5&lorder=5&direction=down title="down">
<img src="/images/down.gif" alt="down">
</a>


<?php
// this code assumes that you are connected to a mysql database prior to
// updating these tables.

if(array_key_exists('lorder',$_GET) and $_GET['direction'] == 'up')
{
  // change position with element above.
  $row_to_change = $_GET['id'];
  $new_lorder = $_GET['lorder'] - 1;
  // update previous record
  $query1 = "UPDATE linktable SET lorder=lorder+1 where lorder = " . $new_lorder;
  mysql_query($query1);
  $query2 = "UPDATE linktable SET lorder=".$new_lorder." where id = " . $row_to_change;
  mysql_query($query2);
}
elseif (array_key_exists('lorder',$_GET) and $_GET['direction'] == 'down')
{
  // change position with element below.
  $row_to_change = $_GET['id'];
  $new_lorder = $_GET['lorder'] + 1;
  // update previous record
  $query1 = "UPDATE linktable SET lorder=lorder-1 where lorder = " . $new_lorder;
  mysql_query($query1);
  $query2 = "UPDATE linktable SET lorder=".$new_lorder." where id = " . $row_to_change;
  mysql_query($query2);
}
else
{
  //do nothing
}
// build your table here

?>

Joseph Melnick



0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question