Jump to content

Recommended Posts

$dateInLastHour = strtotime('-1 hours');
$dateInLastDay = strtotime('-1 days');
$dateInLastWeek = strtotime('-1 weeks');

    $stmt = $pdo->prepare("SELECT string, q_id, count(string), date FROM queries WHERE IP=? AND session_tokn=?  AND cleared=0 AND date > ? GROUP BY string ORDER BY q_id DESC LIMIT 200");
$stmt->execute([$ip,  $_SESSION["history"], $dateInLastHour]); 
echo "<ul>";
while ($row = $stmt->fetch()) {

    if($row['count(string)'] == 1){
    echo "<li><a title='".$row['date']."' href='?q=".$row['string']." ' >\"".$row['string']."\"</a></li> ";
    } else {
    echo "<li><a title='".$row['date']."'  href='?q=".$row['string']." ' >\"".$row['string']."\"</a> <small>(x".$row['count(string)'].")</small> </li>";
    }
}
echo "</ul>";
echo "</div></small></center>";

Hey freaks. Why can't i get this working? I'm planning on having three loops, one for hour, one for day and the other for week.. I'm really bad at interpreting maths but ok at conditionals.. help please. :) 

 

Should show the results in terms of the time scales

Edited by oz11
Link to comment
https://forums.phpfreaks.com/topic/317304-from-the-last-week-day-hour/
Share on other sites

You do realise that id and date values returned by that query could be from any arbitrary record in the group and therefore meaningless, don't you?

17 minutes ago, oz11 said:

Why can't i get this working?

Define "working".

P.S.

Instead of runnning 3 queries you could do something like this

SELECT string
     , SUM(CASE WHEN date > NOW() - interval 1 HOUR THEN 1
                ELSE 0
                END) as lastHour
     , SUM(CASE WHEN date > NOW() - interval 1 DAY THEN 1
                ELSE 0
                END) as lastDay
     , SUM(CASE WHEN date > NOW() - interval 7 DAY THEN 1
                ELSE 0
                END) as lastWeek
FROM queries
GROUP BY string;

giving

image.png.1846c2b90f36a89a186bd782250a55a3.png

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.