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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:07:01+00:00 2026-05-21T09:07:01+00:00

I have a script to print appointments from a mysql db, There is 2

  • 0

I have a script to print appointments from a mysql db, There is 2 foreach loops, one to print the date, and one to print the appointments related to that date. However the second foreach loop only prints the first item from each date.

<?php
error_reporting(0);
session_start();
require('sessions.inc.php');
Include('config.inc.php');

if(!isLoggedIn())
{
   echo("not logged in");
}
else
{
//form
   echo('  <html>
        <center><h1>Add new Appontment</h1></center>
        <form name="login" action="diary.php" method="post">
        Date (YYYY-MM-DD): <input type="text" name="date"/><br>
        Time (HH-MM-SS):<input type="text" name="time"/><br>
        Description:<input type="descrip" name="descrip"/><br>
        Place:<input type="place" name="place"/><br>
        <input type="submit" value="sumbit"/>
        </form>
        </html>
        ');

//Connect to DB
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname);


//Get Data from DB

$query = "SELECT id,title,date,time,place FROM tbl_diary GROUP BY date;";
$result = mysql_query($query) or die(mysql_error());

//Get Data from form
$date = mysql_real_escape_string($_POST['date']);
$time = mysql_real_escape_string($_POST['time']);
$descrip = mysql_real_escape_string($_POST['descrip']);
$place = mysql_real_escape_string($_POST['place']);

//insert into DB
if (isset($_POST['date'],$_POST['time'],$_POST['descrip'],$_POST['place']))
{
    $insert = "INSERT INTO tbl_diary (date,time,title,place) VALUES ('$date','$time','$descrip','$place')";

        if (!mysql_query($insert))
        {
            die('Error: ' . mysql_error());
        }
    echo ('New appontment at'.$_POST['place'].'added, On'.$_POST['date'].".<br>");
    echo ('<a href="./index.php?page=diary">Please click to reload page</a>');
}

//Intizlize array
$array = array();


//Display appontments


while($input = mysql_fetch_array($result))

 {
    if (!isset($array[$input['date']]))
    {
        $array[$input['date']] = array();
    }
    //put to end of array
    $array[$input['date']] []= $input;
}
//The first for each prints each date, The second prints the times.
foreach ($array as $TheDate => $items)
{
$therealdate = date("d-m-Y", strtotime($TheDate));
//welcome to europe MySql

    echo '<h1>'.$therealdate.'</h1>';
    echo "<ul>";

    foreach ($items as $item)
    {
        echo "<li>{$item['time']}: {$item['title']} "."@ {$item['place']}</li>";
    }

echo "</ul>";
}
//exit
echo ('<a href="./main.php">Return to main</a>');
}
?>
  • 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-05-21T09:07:01+00:00Added an answer on May 21, 2026 at 9:07 am

    There’s a problem in your mysql query string.

    SELECT id,title,date,time,place FROM tbl_diary GROUP BY date;
    

    This query grab only a row if date are the same.

    Try this:

    SELECT id,title,date,time,place FROM tbl_diary;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that grabs data from a MySQL database table and creates
I have a CGI script that prints the following on stdout: print Status: 302
I have a script that retrieves objects from a remote server through an Ajax
I have a script that checks responses from HTTP servers using the PEAR HTTP
I have one groovy script which print some statistics: println: ... now I have
I need to write a PHP script that will print out results from a
I have a script that loops through a series of four (or less) characters
I have a script that I want to make sure only one is running,
I have a script, called test.py , that does the following: while (1): ....print
I have a script that runs from a newly created shell. OS is Red

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.