Jump to content

Sorting according to time


fierdor

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

$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...

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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....

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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())

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.