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? Quote Link to comment Share on other sites More sharing options...
revraz Posted February 13, 2008 Share Posted February 13, 2008 Make them UNIQUE in the DB Field. Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
schilly Posted February 13, 2008 Share Posted February 13, 2008 You could probably javascript it pretty easy. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. 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.