oz11 Posted September 19, 2023 Share Posted September 19, 2023 (edited) $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 September 19, 2023 by oz11 Quote Link to comment https://forums.phpfreaks.com/topic/317304-from-the-last-week-day-hour/ Share on other sites More sharing options...
Barand Posted September 19, 2023 Share Posted September 19, 2023 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". Quote Link to comment https://forums.phpfreaks.com/topic/317304-from-the-last-week-day-hour/#findComment-1611969 Share on other sites More sharing options...
Barand Posted September 19, 2023 Share Posted September 19, 2023 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 Quote Link to comment https://forums.phpfreaks.com/topic/317304-from-the-last-week-day-hour/#findComment-1611972 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.