Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8262197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:41:18+00:00 2026-06-08T03:41:18+00:00

My database table have 5 columns: ‘id’, ‘date_visited’, ‘page_title’, ‘ip’ and ‘total_views’. I am

  • 0

My database table have 5 columns: ‘id’, ‘date_visited’, ‘page_title’, ‘ip’ and ‘total_views’.
I am not able to display ORDER BY ‘date_visited’.
My PHP Query is:

<?php
[...]
$query = "SELECT *,count(*) FROM table WHERE ip GROUP BY page_title";
$result = mysqli_query($link,$query) or die(mysqli_error($link). "Q=".$query);
if(!$result == 0) {
    while ($row = mysqli_fetch_array($result)) {
        $dataList_br .= '<tr>
                            <td>' .$row['date_visited']. '</td>
                            <td>' .$row['page_title']. '</td>
                            <td>' .$row['count(*)']. '</td>
                        </tr>';
    }
} else {
    $dataList_br .= '<p class="warning">No data found in database.</p>';
}
?>

When it outputs, it displays [date][page title] and [total views].
Please someone help me, how do I display last date from the query, instead now it displays the very first day the page was visited.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:41:19+00:00Added an answer on June 8, 2026 at 3:41 am

    MySQL is lenient about the contents of the GROUP BY and will return a row for the group somewhat arbitrarily if columns aren’t in the GROUP BY but are SELECTed. In your case, it just gave you the first row (lowest date) for each group.

    Get the page_name of the row with the MAX(date_visited) per group and join that against the main table to pull in the remaining columns from the main table.

    SELECT
      table.id,
      table.ip,
      table.total_views,
      maxdates.date_visited,
      maxdates.page_name,
      maxdates.thecount
    FROM
      table
      JOIN (
        /* Subquery returns the aggregates to join against 
           the main table so other columns can be pulled in */
        SELECT 
          page_title, 
          MAX(date_visited) AS maxdate, 
          COUNT(*) AS thecount 
        FROM table 
        GROUP BY page_title
      ) maxdates
        ON table.page_name = maxdates.page_name 
           AND table.date_visited = maxdates.maxdate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two columns(column1, column2) in my oracle database table named as demo .
I have 3 columns in Oracle database having table mytable and i want records
Suppose I have a database table with columns a, b, and c. I plan
I have one database table which contains 8 columns. One of the columns is
Lets say we have a database table with two columns, entry_time and value. entry_time
I have a java class containing all the columns of a database table as
I have three mysql table from same database Db1. Three tables have following columns.
I Have a DataBase in my project With Table named 'ProcessData' and columns named
I have a Database (SQL Server) with table named 'ProcessData' and columns named 'Process_Name'
i have latitude and longitude columns in location table in PostgreSQL database, and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.