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

  • SEARCH
  • Home
  • 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 9156977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:54:01+00:00 2026-06-17T12:54:01+00:00

So i have code for a very simple calendar, however I can’t figure out

  • 0

So i have code for a very simple calendar, however I can’t figure out how to query mysql database to find any events for each day of the month. I know how to query the database for that information, but i dont know where i would put it in the code of creating a calendar or how to structure it or anything. ive looked at many codes of php calendars and for each code i havent been able to get data from my database, i just have no idea how to do it. any help is grateful, thanks.
calendar code editted to include db stuff:

include ("connection.php"); 

$date =time (); 
$day = date('d', $date); 
$month = date('m', $date); 
$month = $month + "02";
$year = date('Y', $date); 
$years = substr($year, 2, 2);

$first_day = mktime(0,0,0,$month, 1, $year); 
$title = date('F', $first_day); 
$day_of_week = date('D', $first_day); 
switch($day_of_week){ 
    case "Sun": $blank = 0; break; 
    case "Mon": $blank = 1; break; 
    case "Tue": $blank = 2; break; 
    case "Wed": $blank = 3; break; 
    case "Thu": $blank = 4; break; 
    case "Fri": $blank = 5; break; 
    case "Sat": $blank = 6; break; 
}

$days_in_month = cal_days_in_month(0, $month, $year);
echo "<table border=1 width=294>";
echo "<tr><th colspan=7> $title $year </th></tr>";
echo "<tr><td width=42>S</td><td width=42>M</td><td 
width=42>T</td><td width=42>W</td><td width=42>T</td><td 
width=42>F</td><td width=42>S</td></tr>";
$day_count = 1;
echo "<tr>";

while ( $blank > 0 ) 
{ 
    echo "<td></td>"; 
    $blank = $blank-1; 
    $day_count++;
} 
$day_num = 1;
 while ( $day_num <= $days_in_month ) 
{ 

echo "<td> $day_num <br/>";


$result = mysql_query("SELECT time, length FROM hire WHERE day = '$day_num' and month =    '$month' and year = '$years'") or die ('Error: '.mysql_error ());

while ($row = mysql_fetch_array($result)){

$time = $row['time'];
$length = $row['length'];

}

if (isset($time) and (isset($length))) {
 echo "Time: " . $time . "<br/> Length: " . $length . "<br/>";
}

"</td>";



    $day_num++; 
    $day_count++;
        if ($day_count > 7)
        {
        echo "</tr><tr>";
        $day_count = 1;
        }

} 

while ( $day_count >1 && $day_count <=7 ) 
{ 
    echo "<td> </td>"; 
    $day_count++; 
} 

echo "</tr></table>"; 
  • 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-17T12:54:02+00:00Added an answer on June 17, 2026 at 12:54 pm

    You’ll need to put your database code to the place where the date cells are outputted. Here’s the code:

    <?php
    include ("connection.php"); 
    
    $date =time (); 
    $day = date('d', $date); 
    $month = date('m', $date); 
    $month = $month + "01";
    $year = date('Y', $date); 
    
    $first_day = mktime(0,0,0,$month, 1, $year); 
    $title = date('F', $first_day); 
    $day_of_week = date('D', $first_day); 
    switch($day_of_week){ 
        case "Sun": $blank = 0; break; 
        case "Mon": $blank = 1; break; 
        case "Tue": $blank = 2; break; 
        case "Wed": $blank = 3; break; 
        case "Thu": $blank = 4; break; 
        case "Fri": $blank = 5; break; 
        case "Sat": $blank = 6; break; 
    }
    
    $days_in_month = cal_days_in_month(0, $month, $year);
    echo "<table border=1 width=294>";
    echo "<tr><th colspan=7> $title $year </th></tr>";
    echo "<tr><td width=42>S</td><td width=42>M</td><td width=42>T</td><td width=42>W</td><td width=42>T</td><td width=42>F</td><td width=42>S</td></tr>";
    $day_count = 1;
    echo "<tr>";
    
    while ( $blank > 0 ) 
    { 
        echo "<td></td>"; 
        $blank = $blank-1; 
        $day_count++;
    } 
    $day_num = 1;
     while ( $day_num <= $days_in_month ) 
    { 
        //database code here
        $result = ''; //formatted html result
        echo "<td> $day_num $result</td>"; 
        $day_num++; 
        $day_count++;
        if ($day_count > 7)
        {
            echo "</tr><tr>";
            $day_count = 1;
        }
    } 
    
    while ( $day_count >1 && $day_count <=7 ) 
    { 
        echo "<td> </td>"; 
        $day_count++; 
    } 
    
    echo "</tr></table>"; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This should be a very simple code, but I can't figure it out. Basically
I have very simple code that cause my MySQL db to hang: import sqlalchemy
I have a very simple table and I can happily query it using LINQ
The below code is very simple. I have a jQuery autocomplete bound to an
I have a very simple code: package mygame; public class RunGame { public static
I have some VERY simple code to return the title for a section header:
I have a very simple code, which annoyingly was working and for the life
I have the following very simple code snippet which is loaded from a separate
I have got the following very simple code: function init() { var articleTabs =
I have a big problem with very simple code. I need to get a

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.