Solved

simple link ordering

Posted on 2006-07-01
7
251 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now