Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

make a timtable in html from information from mysql

Posted on 2009-04-03
6
Medium Priority
?
538 Views
Last Modified: 2013-12-12
I have a table:
WEEKTIMETABLE
---------------
username varchar(10)
day varchar(10)
Time varchar(10)
Subject varchar(100)(this is the description)
CourseCode varchar(10)
Semester int(1)
CourseYear(1)

I want to make a html timetable by selecting certain rows from the database using php commands.
Example

time        Monday tuesday wednesday thursday friday saturday sunday
______________________
09.00     lecture   party  
10.00
11/00

etc....
how would i make a table like this and for each day-time slot take the info for example
select subject
from weeklytimetable
where day = 'Monday' and time = '09.00' and username = userinsession

thanks a million for any help you can give!!
0
Comment
Question by:AnnMarieB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 6

Expert Comment

by:twocandles
ID: 24058343
You issue your query ordered by time and day (attention: first field time, not date) filtering for the next 7 days (so no day is repeated!). Then, (in pseudocode) program this algorithm:

<tr>
<td>
if( currentrecord.day == monday ) and ( currentrecord.time == 9:00 )
{
  echo( subject );
  currentrecord = nextrecord;
}
</td>
<td>
if( currentrecord.day == tuesday ) and ( currentrecord.time == 9.00 )
{
  echo( subject );
   currentrecord = nextrecord;
 }
</td>

And so on. When you reach the end of the week, then change the row: </tr>

Of course, this can be optimized using arrays so you don't have to write an if for every day and time.
0
 

Author Comment

by:AnnMarieB
ID: 24058398
thanks for your help but dont understand the currentrecord = nextrecord;
and how would i say if (weeklytimetable.day = monday and weeklytimetable = tuesday and weeklytimetable = 'currentuserinsession)
echo subject;
0
 

Author Comment

by:AnnMarieB
ID: 24058401
sorry i meant
(weeklytimetable.day = monday and weeklytimetable.time =09.00 and weeklytimetable.username = 'currentuserinsession)
0
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 6

Accepted Solution

by:
twocandles earned 1500 total points
ID: 24059168
currentrecord = nextrecord;

means to process next record.

If you want the results for only one user, then filter it in you query. Take a look at the code. It's not a working solution but it'll give an idea. I didn't take care of possible errors.

The table you're using stores time and day as varchars ... it may be a problem when ordering unless you prepend a 0 for times lower than 10.00. The days may become a problem too. Maybe you should order the results programatically.



<?php
 
// Here you build up your query. I made a guess using username 
// from your session. Also you'll need some logic to calculate 
// previous_monday and next_sunday
$sql = "SELECT day, Time, Subject
        FROM   WEEKTIMETABLE
        WHERE  username = ".$_SESSION["username"]
          AND  previous_monday <= day and day <= next_sunday
        ORDER by Time, day;
 
// You should have a valid connection to the db before using
// this command. 
$res= mysql_query($sql);
 
// Get the rows as an associative array
$row = mysql_fetch_assoc($res);
 
// Now start building the actual html
// Display the header (first row) of your table with the day names.
 
<tr>
<td>9.00</td>
<td>
<?
// First check if $row contains a valid value, and then check if
// matches the day-time you're about to print
if( ( $row ) && ( $row["day"] == "Monday" ) && ( $row["Time"] == "9.00" ) )
{
    echo $row["Subject"];
    $row = mysql_fetch_assoc($res);
}
?>
</td>
 
// Now repeat that for every time and day
?>

Open in new window

0
 

Author Comment

by:AnnMarieB
ID: 24059520
thanks for your help but no matter what i change the error comes out
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\StudentOrganiser\Noname3.php on line 8 and i have a connection to the database
0
 
LVL 6

Expert Comment

by:twocandles
ID: 24059915
Could you post your code, please?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
The viewer will learn how to dynamically set the form action using jQuery.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question