gple Posted February 13, 2008 Share Posted February 13, 2008 I have a list of documents in which the name gets outputted onto a website. I created another column in the table to distinguish which order they should appear in. so I have 10 records and each of them has a different number next to it (1-10) and this will be the order that they appear in. How can I make sure that the user does not put the same number for two different records? Link to comment https://forums.phpfreaks.com/topic/90946-ordering/ Share on other sites More sharing options...
revraz Posted February 13, 2008 Share Posted February 13, 2008 Make them UNIQUE in the DB Field. Link to comment https://forums.phpfreaks.com/topic/90946-ordering/#findComment-466113 Share on other sites More sharing options...
Isityou Posted February 13, 2008 Share Posted February 13, 2008 There should be a better way, but heres a soultion <?php $sql = "SELECT sort_number? FROM table_name"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { if($user_input == $row[0]) { // We found a matching sort number!! die('That sort number has been taking'); } } ?> In theory should work. Link to comment https://forums.phpfreaks.com/topic/90946-ordering/#findComment-466116 Share on other sites More sharing options...
rhodesa Posted February 13, 2008 Share Posted February 13, 2008 There is no logical reason you can't allow 2 order numbers that are the same. I do it all the time. When you select the records from the DB with the sort, if they have the same number, then the older record will be first. Do you have a reason they can't use the same number? Link to comment https://forums.phpfreaks.com/topic/90946-ordering/#findComment-466134 Share on other sites More sharing options...
Isityou Posted February 13, 2008 Share Posted February 13, 2008 Of course theres a logical reason. Say I want to order my pages in order from one through ten. Each page would have its own unique sort number. Link to comment https://forums.phpfreaks.com/topic/90946-ordering/#findComment-466143 Share on other sites More sharing options...
schilly Posted February 13, 2008 Share Posted February 13, 2008 You could probably javascript it pretty easy. Link to comment https://forums.phpfreaks.com/topic/90946-ordering/#findComment-466148 Share on other sites More sharing options...
rhodesa Posted February 13, 2008 Share Posted February 13, 2008 Sorry...logical was the wrong word....but there is no requirement. And, from a UI standpoint, I would much rather be able to put the same number in twice to move a record then change all of the numbers Link to comment https://forums.phpfreaks.com/topic/90946-ordering/#findComment-466149 Share on other sites More sharing options...
Isityou Posted February 13, 2008 Share Posted February 13, 2008 To solve this problem you can store the sort identifiers in an array and when you replace a sort identifier with an existing it pushes the array +1 so you wont have to change every identifier after every new entry. Link to comment https://forums.phpfreaks.com/topic/90946-ordering/#findComment-466152 Share on other sites More sharing options...
gple Posted February 13, 2008 Author Share Posted February 13, 2008 Is there anyway I could make a list and move them up and down in a list and then have the order number change as such. Link to comment https://forums.phpfreaks.com/topic/90946-ordering/#findComment-466153 Share on other sites More sharing options...
rhodesa Posted February 13, 2008 Share Posted February 13, 2008 Or better yet, just get rid of the numbers and use one of the many JavaScript dragable libraries Link to comment https://forums.phpfreaks.com/topic/90946-ordering/#findComment-466154 Share on other sites More sharing options...
rhodesa Posted February 13, 2008 Share Posted February 13, 2008 Here is a commonly used one: http://demo.script.aculo.us/ajax/sortable_elements Link to comment https://forums.phpfreaks.com/topic/90946-ordering/#findComment-466155 Share on other sites More sharing options...
Isityou Posted February 13, 2008 Share Posted February 13, 2008 Yeah a JavaScript draggable list would be a good solution to this problem. You can simply drag and sort. Link to comment https://forums.phpfreaks.com/topic/90946-ordering/#findComment-466156 Share on other sites More sharing options...
gple Posted February 13, 2008 Author Share Posted February 13, 2008 I like the way it works, but then I want to store the order in which they appear into a table so that on the front end, the viewer can see what I order I put it in. Link to comment https://forums.phpfreaks.com/topic/90946-ordering/#findComment-466162 Share on other sites More sharing options...
Isityou Posted February 13, 2008 Share Posted February 13, 2008 Yeah, store the order identifiers in an array when you use the draggable list, make a form that send post data to PHP that will then update the database sort identifiers. I've created a draggable list before that changes the sort order of pages, I can show you if you like. Link to comment https://forums.phpfreaks.com/topic/90946-ordering/#findComment-466167 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.