Jump to content

real hard database sort problam cheers.


redarrow

Recommended Posts

i got a real hard problam here i have tried DESC and ASC but no joy and all the orders under the sun but i can not get the database while loop to ASC the last time_check from the loop to go into varable time check.

please help.

from the database the times from the while loop.
[code]
10:06:1410:46:2810:46:5012:44:4112:46:5805:04:5405:30
:4310:18:3110:18:4710:23:0410:24:1010:28:5910:56:3810:58:1010:58:2510:58:42
[/code]

i need time_check to be the last time_check in the while loop == 10:58:42
[code]
$query_time="select * from member_topics where user_id='$user_id'";

$result_time=mysql_query($query_time);

while($timmed=mysql_fetch_assoc($result_time)){


$time_check=$timmed['time_added'];


echo $time_check;

}
[/code]
Link to comment
Share on other sites

<?php

$query_time="select `time_added` from `member_topics` where `user_id`='$user_id' ORDER BY `time_added` DESC";

$result_time=mysql_query($query_time);

$timmed=mysql_fetch_assoc($result_time);

$time_check=$timmed['time_added'];

?>

That should do it.
Link to comment
Share on other sites

[quote author=redarrow link=topic=103158.msg410606#msg410606 date=1154862047]
that the problam it is holding the first time

i am getting 10;06;14 the first entry
[/quote]

Are you sure, because if that is the value you want, and that is the last value that was echoed, that should be the value $time_check should end up holding when the while loop finishes. But to be honest this is a poor way of entering time values into a database, you should store a timestamp and convert it into the date format you want, then you can get MySQL to sort it in whichever order you like. As it stands a sort won't work because the time values appear to be in 12 hour format.
Link to comment
Share on other sites

that last post was near but didnt work all it done was add time to a time that was not in the database going mad ..............

[code]

<?php

$query_time="select * from member_topics where user_id='$user_id' ORDER BY time_added desc";

$result_time=mysql_query($query_time);

$timmed=mysql_fetch_assoc($result_time);

$time_check=$timmed['time_added'];
echo $time_check;


$check=strtotime($time_check);
echo "<br>$check<br>";

$time_know=time()-10;

echo "<br>$time_know<br>";

if($check > $time_know){


echo "<html><body vlink='black' alink='black' link='black'><br><br><br><table bordercolor='black'border='4'

align='center'><td align='center'><h1><font color='red'>Blob it! </font> <h1>Post valadation

Warning!</h1></td></table><br><div align='center'></font><br><br><b>You must wait 2 minutes to post your next

blog!</b><br><br><font color='red'>Please use this link to see all our <a href='see.php'>Blogs</a></font>
<br><br><br><br><br><br><br><br><br><br><br><br><br><hr color='black'><font color='red'>((c))Admin@blogit.com --blog it!

--</font><hr color='black'></hr></body></html></div>";

exit;
}
?>
[/code]
Link to comment
Share on other sites

know shows all the times madness hay any idears ans cheers.

[code]
<?php

$query_time="select * from member_topics where user_id='$user_id' ORDER BY time_added desc";

$result_time=mysql_query($query_time);

while($timmed=mysql_fetch_assoc($result_time)){

$time_check=$timmed['time_added'];
echo $time_check;
}

$check=strtotime($time_check);
echo "<br>$check<br>";

$time_know=time()-10;

echo "<br>$time_know<br>";

if($check > $time_know){


echo "<html><body vlink='black' alink='black' link='black'><br><br><br><table bordercolor='black'border='4'

align='center'><td align='center'><h1><font color='red'>Blob it! </font> <h1>Post valadation

Warning!</h1></td></table><br><div align='center'></font><br><br><b>You must wait 2 minutes to post your next

blog!</b><br><br><font color='red'>Please use this link to see all our <a href='see.php'>Blogs</a></font>
<br><br><br><br><br><br><br><br><br><br><br><br><br><hr color='black'><font color='red'>((c))Admin@blogit.com --blog it!

--</font><hr color='black'></hr></body></html></div>";

exit;
}
?>
[/code]
Link to comment
Share on other sites

Change this:
[code]
$result_time=mysql_query($query_time);

while($timmed=mysql_fetch_assoc($result_time)){

$time_check=$timmed['time_added'];
echo $time_check;
}
[/code]

to this:

[code]
$result_time=mysql_query($query_time);

while($timmed=mysql_fetch_assoc($result_time)){

$time_check=$timmed['time_added'];
}
echo $time_check;
[/code]
Link to comment
Share on other sites

solved dont know why but works like this.

[code]
<?php

$query_time="select time_added from member_topics where user_id='$user_id' ORDER BY time_added ";

$result_time=mysql_query($query_time);

while($timmed=mysql_fetch_assoc($result_time)){

$time_check=$timmed['time_added'];
}

$check=strtotime($time_check);

$time_know=time()-60;

echo "<br>$time_know<br>";

if($check > $time_know){


echo "<html><body vlink='black' alink='black' link='black'><br><br><br><table bordercolor='black'border='4'

align='center'><td align='center'><h1><font color='red'>Blob it! </font> <h1>Post valadation

Warning!</h1></td></table><br><div align='center'></font><br><br><b>You must wait 2 minutes to post your next

blog!</b><br><br><font color='red'>Please use this link to see all our <a href='see.php'>Blogs</a></font>
<br><br><br><br><br><br><br><br><br><br><br><br><br><hr color='black'><font color='red'>((c))Admin@blogit.com --blog it!

--</font><hr color='black'></hr></body></html></div>";

exit;
}
[/code]
Link to comment
Share on other sites

Note that if you only want the last time entry for the user you can also use the MYSQL function MAX()
[code]
SELECT MAX(timecolumn) AS timecolumn FROM etc WHERE userid = etc
[/code]
[url=http://dev.mysql.com/doc/refman/4.1/en/group-by-functions.html]Aggregate Functions[/url]
Link to comment
Share on other sites

The problem is that he seems to be adding times in 12 hour format so any kind of sort won't work - he has to rely on getting the last row inserted, which isn't very reliable.  Redarrow you should at least store the time and date together so you can sort them properly before pulling the data out. I would do it with a timestamp inserted with NOW() in the query, then when pulling it out use "UNIX_TIMESTAMP(time_added) as time_stamp" in the query, then you can compare that directly with the current time with "if $time_stamp > time() - 120" etc...
Link to comment
Share on other sites

[quote author=king arthur link=topic=103158.msg410640#msg410640 date=1154865990]
The problem is that he seems to be adding times in 12 hour format so any kind of sort won't work - he has to rely on getting the last row inserted, which isn't very reliable.  Redarrow you should at least store the time and date together so you can sort them properly before pulling the data out. I would do it with a timestamp inserted with NOW() in the query, then when pulling it out use "UNIX_TIMESTAMP(time_added) as time_stamp" in the query, then you can compare that directly with the current time with "if $time_stamp > time() - 120" etc...
[/quote]

I should have read the thread more closely. I'd have to agree. You should be storing the information in the way suggested by king arthur. After doing that you can add an index on (user_id_column, datetime column) and use the MAX() function as described.
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.