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
https://forums.phpfreaks.com/topic/38361-element-ordering/
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
https://forums.phpfreaks.com/topic/38361-element-ordering/#findComment-185200
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
https://forums.phpfreaks.com/topic/38361-element-ordering/#findComment-185225
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.