Jump to content

Element ordering


mb81

Recommended Posts

Hey Guys,

 

I have a project where the user is able to select the order of items for display using up and down buttons. I have used systems like this before, but have run into problems with gaps in the sequencing or getting duplicate numbers in the ordering sequence. Are there any algorithms that other people have used for this type of thing?

 

Thanks,

Matt

Link to comment
Share on other sites

I know what you're talking about, but I don't understand the problem? What is your problem with the gaps and duplicate numbers?

 

I usually loop through the results of the user's ordering and assign them into an array, so that removes the gaps/dupes.

Link to comment
Share on other sites

table {field1, field2, field3, ...}

elements {id, name, order, ...}

 

Let them designate the order as an integer, but when you display the items don't display the order thats in the table, display an order from a counter variable.

 

SELECT * FROM elements WHERE 1 ORDER BY order;

 

<?php
$q = mysql_query($sql);
if($q){
  $count = 1;
  while($row = mysql_fetch_assoc($q)){
    echo $count++ . ": " . $row['name'];
  }
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.