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 9190657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:30:47+00:00 2026-06-17T20:30:47+00:00

I have table entries in my database with structure: id | card | event

  • 0

I have table entries in my database with structure:

id | card | event | time | day | hm
  • > id – is unique ID of each entry.
  • > card – is number.
  • > event – is number (0, 1, 2, or 3)
  • > time – is mysql_timestamp
  • > day – is day of month when entry was added (date(“j”, time())
  • > hm – some other info…

I want to display all entries for one month in html table.
Now I’m using this simple query:

$sql = "SELECT event, time, day, hm FROM `entries` 
WHERE card=$card_t 
AND YEAR(time)=$year 
AND MONTH(time)=$month
AND event IN (0,1,3) 
ORDER BY `time` ASC;";

Conditions of output:
table must have minimum one row for a day (31 rows for January).
if there is no entries for day(1-31) row must be:

if there is only two entries for day row must be:

<tr>
   <td>$day_number</td>
   <td>$time_of_first_event</td>
   <td>$first_event</td>
   <td>$time_of_last_event</td>
   <td>$last_event</td>
 </tr>

 if there is more than two entries a day two must be (I will hide second one with jquery later):

  <tr>
   <td>$day_number</td>
   <td>$time_of_first_event</td>
   <td>$first_event</td>
   <td>$time_of_last_event</td>
   <td>$last_event</td>
 </tr>
 <tr>
     <table>
       <tr>
        <td>$time</td>
        <td>$event</td>
       </tr>
     </table>
 </tr>

So it looks like:

| 1 | no entry                                          |
| 2 | no entry                                          |
| 3 | no entry                                          |
| 4 | time_first | event_fisrt | time_last  |event_last |
                 | time2 | event 2                      |
                 | time3 | event 3                      |
| 5 | no entry                                          |
... 

But all i got now is output of 31 row and if one day have more than it duplicates this day row and displays all rows for this day:

| 1 | no entry       |
| 2 | no entry       |
| 3 | no entry       |
| 4 | time1 event 1  |
| 4 | time2 event 2  |
| 4 | time3 event 3  |
| 5 | no entry       |
...

Please help me guys and sorry for mistakes, english is not my native lang.

  • 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-17T20:30:48+00:00Added an answer on June 17, 2026 at 8:30 pm

    Use GROUP_CONCAT in sql and explode foreach loop

    $sql = 
    
    
    "SELECT 
            GROUP_CONCAT(event SEPARATOR ","), GROUP_CONCAT(time SEPARATOR ","), 
            day , GROUP_CONCAT(hm SEPARATOR ",") FROM `entries` 
        WHERE 
            card=$card_t 
            AND YEAR(time)=$year 
            AND MONTH(time)=$month
            AND event IN (0,1,3) 
        GROUP BY 
            day
        ORDER BY 
            `time` ASC;";
    

    In foreach,

    foreach ($entries as $entry) {
        if ($entry['event'] == "") {
            echo '<tr>';
                 echo '<td>'.$no++.'</td>';
                 echo '<td>No events</td>';
                 ...................
            echo </tr>';
            continue;
        }
    
        $events = explode("," , $entry['event']);
        if (count($events) > 0) {
           // Have multiple row here
           foreach($events as $event) {
               ........................
           }
        } else {
            echo '<tr>';
                 echo '<td>'.$no++.'</td>';
                 echo '<td>'.$entry['event'].'</td>';
                 ...................
            echo </tr>';
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table with a unique auto-incremental primary key. Over time, entries may be
I have a table with entries which has a DATE field. Each entry has
I have a database table that contains entries for start time and end time
I have a database with 75,000+ rows with 500+ entries added per day. Each
I have a simple database structure like this: entries table +----+-----------+------------+-----------+------+ | id |
First time post. As an example, say I have a table with 12 entries;
I have a database-table with the following structure: id1 | id2 | weight Now
Following is the problem statement: I have a database table with entries that look
I have a table in my SQL Anywhere 12.0.1 database: CREATE TABLE Entries (
I have a simple database table called Entries: class CreateEntries < ActiveRecord::Migration def self.up

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.