Jump to content

Ordering


gple

Recommended Posts

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

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

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

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.