fierdor Posted January 6, 2009 Share Posted January 6, 2009 How do you sort entries according to time?? As in I have a quiz competition and i have a corresponding scoreboard...Now if sumone answers a question his level gets updated and is reflected in the scoreboard..But the problem is if sumone else answers after him bt his name is alphabetically first the second guy becomes first!! Is there a solution to like sort acc to time&&level or sum oder easier solution? Quote Link to comment https://forums.phpfreaks.com/topic/139641-sorting-according-to-time/ Share on other sites More sharing options...
xtopolis Posted January 6, 2009 Share Posted January 6, 2009 Yes. ORDER BY column ASC, column DESC Quote Link to comment https://forums.phpfreaks.com/topic/139641-sorting-according-to-time/#findComment-730643 Share on other sites More sharing options...
fierdor Posted January 6, 2009 Author Share Posted January 6, 2009 No not that way...I am doing that already i.e sort people by level DESC so that people on higher levels will cum at the top...What i am talking about is the people at the same level....Here those who are alphabetically first will be higher even though they might not be chronologically first there. Quote Link to comment https://forums.phpfreaks.com/topic/139641-sorting-according-to-time/#findComment-730689 Share on other sites More sharing options...
Mark Baker Posted January 6, 2009 Share Posted January 6, 2009 No not that way...I am doing that already i.e sort people by level DESC so that people on higher levels will cum at the top...What i am talking about is the people at the same level....Here those who are alphabetically first will be higher even though they might not be chronologically first there. Read and reread what you were told: ORDER BY level ASC, answerTime DESC Quote Link to comment https://forums.phpfreaks.com/topic/139641-sorting-according-to-time/#findComment-730692 Share on other sites More sharing options...
xtopolis Posted January 6, 2009 Share Posted January 6, 2009 Yes. ORDER BY column ASC, column DESC SELECT name, level FROM yourTable ORDER BY level DESC, name ASC Quote Link to comment https://forums.phpfreaks.com/topic/139641-sorting-according-to-time/#findComment-730693 Share on other sites More sharing options...
fierdor Posted January 6, 2009 Author Share Posted January 6, 2009 Hmm...ok...But is there a function to get the time at which the user entered the answer?? Sorry I have no experience in dealing with time-related PHP functions Quote Link to comment https://forums.phpfreaks.com/topic/139641-sorting-according-to-time/#findComment-730695 Share on other sites More sharing options...
redarrow Posted January 6, 2009 Share Posted January 6, 2009 That means put level at the top of name so if level is higher then name that level wins with that level. am i wright or wrong. Quote Link to comment https://forums.phpfreaks.com/topic/139641-sorting-according-to-time/#findComment-730696 Share on other sites More sharing options...
fierdor Posted January 6, 2009 Author Share Posted January 6, 2009 No no See there is a user named 'bac' and he clears level no 9 first.Then there is another user 'abc' who clears level no 9 later than 'bac'.But because his name is alphabetically before 'bac' his name is higher than 'bac' though 'bac' cleared the level earlier than 'abc'.This is just a special case and it is not necessary that it will happen always. Quote Link to comment https://forums.phpfreaks.com/topic/139641-sorting-according-to-time/#findComment-730699 Share on other sites More sharing options...
redarrow Posted January 6, 2009 Share Posted January 6, 2009 very interesting cheers. Quote Link to comment https://forums.phpfreaks.com/topic/139641-sorting-according-to-time/#findComment-730700 Share on other sites More sharing options...
xtopolis Posted January 6, 2009 Share Posted January 6, 2009 Post your query if you need help. Otherwise it orders by the order that you tell it to. ORDER BY completionTime ASC (depends on if your column type is setup right!) Quote Link to comment https://forums.phpfreaks.com/topic/139641-sorting-according-to-time/#findComment-730707 Share on other sites More sharing options...
fierdor Posted January 8, 2009 Author Share Posted January 8, 2009 $result=mysql_query("SELECT * FROM members ORDER BY level DESC"); This is the query i am currently using...What i want to add is sort TIME OF COMPLETION in ascending. The query is ok..But how to find the TIME OF COMPLETION is a major question...I do not know how to use the PHP time functions... Quote Link to comment https://forums.phpfreaks.com/topic/139641-sorting-according-to-time/#findComment-732221 Share on other sites More sharing options...
xtopolis Posted January 8, 2009 Share Posted January 8, 2009 SELECT * FROM members ORDER BY level DESC, completionTime ASC This is hard to troubleshoot without any info on your table, or code. Quote Link to comment https://forums.phpfreaks.com/topic/139641-sorting-according-to-time/#findComment-732228 Share on other sites More sharing options...
fierdor Posted January 8, 2009 Author Share Posted January 8, 2009 What part of my code or table do you require??The code as such is very big..bt newayz i am posting it here....If u want just specify a particular part u want and i will highlight it...Thanks in advance!! <?php session_start(); include("database.php"); //include("auth.php"); $srno=1; $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("myst", $con); $result=mysql_query("SELECT * FROM members ORDER BY level DESC"); //while($row=mysql_fetch_array($result)) { } //mysql_close($con); ?> <html> <head> <title>MYST - Scoreboard</title> </head> <body> <link href="loginmodule.css" rel="stylesheet" type="text/css"> <div id="Layer1" style="loginmodule.css">MYST</div> <div id="Techno" style="loginmodule.css"> <a href="http://technovanza.org">Technovanza '09</a> - The technical event of VJTI </div> <div id="Layer2" style="loginmodule.css"></div> <!--No clue here--> <div id="Layer3" style="loginmodule.css"> <table width="101%" border="1"> <tr> <td > <b><font color="#0000CC">About Us</font></b> </td> </tr> </table> <table width="101%" border="1" height="328"> <tr> <td height="339"> </td> </tr> </table> </div> <div id="Layer6" style="loginmodule.css"> <table width="101%" border="1"> <tr> <td> <center> <b><font color="#FF0000">Updates!!!</font></b> </center> </td> </tr> </table> <table width="100%" border="1" height="137"> <tr> <td height="158"> <p>So you think its quite difficult solving these few lines. We're here to help you out. Want to know more??????</p> <center> <a href="http://localhost/myst/forum/mboard.php"><img src="images/tab.gif" border="0"></a> </center> </td> </tr> </table> <table width="101%" border="1"> <tr> <td> <div align="center"><b><font color="#0000FF"><a href="scoreboard.php">Scoreboard</a></font></b></div> </td> </tr> </table> <table width="102%" border="1" height="95"> <tr> <td height="135"> </tr> </table> <p> </p> <p> </p> </div> <?php if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) { echo '<ul class="err">'; foreach($_SESSION['ERRMSG_ARR'] as $msg) { echo '<li>',$msg,'</li>'; } echo '</ul>'; unset($_SESSION['ERRMSG_ARR']); } ?> <div id="Layer4" style="loginmodule.css"> <table width="100%" border="1"> <tr> <td> <div align="center"><font color="#FF0000"><b>Scoreboard</b></font></div> </td> </tr> </table> <table id="score" width="100%" border="1"> <tr> <td> <center> <b>Rank</b> </center></td> <td> <center><b>Name </b></center></td> <td> <center><b>Level</b></center> </td> <?php $srno=1; while($row=mysql_fetch_array($result)) { print "<tr>"; print "<td>"; print "<center>"; print $srno; print "</center>"; print "</td>"; print "<td>"; print "<center>"; print $row['login']; print "</center>"; print "</td>"; print "<td>"; print "<center>"; print " ".$row['level']; print "</center>"; print "</td>"; print "</tr>"; $srno++; } mysql_close($con); ?> </table> </div> </body> </html> My mysql table contains member_id,firstname,lastname,login,passwd,level,college,contact,email Quote Link to comment https://forums.phpfreaks.com/topic/139641-sorting-according-to-time/#findComment-732234 Share on other sites More sharing options...
xtopolis Posted January 8, 2009 Share Posted January 8, 2009 You don't seem to have any time columns at all... how do you expect to track times without storing them?! Quote Link to comment https://forums.phpfreaks.com/topic/139641-sorting-according-to-time/#findComment-732235 Share on other sites More sharing options...
fierdor Posted January 8, 2009 Author Share Posted January 8, 2009 That's what I have been asking all along!! How do i track the time of completion of the users in PHP?? Simply put what function should I use in PHP to find out the time at which the user completed a particular level??? After I get that I will get down to inserting that value in the database against the corresponding user in a field...say 'time'.and den i will SORT time ASC.... Quote Link to comment https://forums.phpfreaks.com/topic/139641-sorting-according-to-time/#findComment-732237 Share on other sites More sharing options...
xtopolis Posted January 8, 2009 Share Posted January 8, 2009 I don't know what your application is like! I assume you could track the start time and then the end time using sessions, subtract them and count that as the completion time.. but it really depends on what your application is like! Quote Link to comment https://forums.phpfreaks.com/topic/139641-sorting-according-to-time/#findComment-732240 Share on other sites More sharing options...
fierdor Posted January 8, 2009 Author Share Posted January 8, 2009 It is like this: C there is a answer box on each page...When they enter the answer and the answer is right I need to find that time..I have a part of code where i check the answer and update the level of the user if his answer is right...I can also update his time there and then sort...I just need help with the PHP syntax now... Quote Link to comment https://forums.phpfreaks.com/topic/139641-sorting-according-to-time/#findComment-732241 Share on other sites More sharing options...
xtopolis Posted January 8, 2009 Share Posted January 8, 2009 That doesn't make sense to me. You find what time? The current time? Or the time from page load to correct answer? What time are you storing?! -- a current time, or a time difference value? ~.~ Quote Link to comment https://forums.phpfreaks.com/topic/139641-sorting-according-to-time/#findComment-732246 Share on other sites More sharing options...
fierdor Posted January 8, 2009 Author Share Posted January 8, 2009 The current time at which the user enters the right answer...Basically If sumone answers a question at 11'o clock he shud be ahead of a guy who answers the question at 12'o clock...So i guess that means I will have to record the current time at which he enters the right answer. Quote Link to comment https://forums.phpfreaks.com/topic/139641-sorting-according-to-time/#findComment-732250 Share on other sites More sharing options...
Zane Posted January 8, 2009 Share Posted January 8, 2009 in PHP to get the current time, you simply use the function time from that you can store a list of unix timestamps, which you can convert to regular dates and times or you can use SQL to get the current time. For instance, in your INSERT query you can use the NOW() function which will give you something like this in your database 2009-01-08 23:50:26 so for example. you can go INSERT into tableName (col2, col3, col4, thetimecolum) VALUES ('stuff','stff','styff',NOW()) Quote Link to comment https://forums.phpfreaks.com/topic/139641-sorting-according-to-time/#findComment-732293 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.