mb81 Posted February 13, 2007 Share Posted February 13, 2007 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 Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 15, 2007 Share Posted February 15, 2007 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. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 15, 2007 Share Posted February 15, 2007 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']; } } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.