Solved

make a timtable in html from information from mysql

Posted on 2009-04-03
6
508 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
  • 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 6

Accepted Solution

by:
twocandles earned 500 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

770 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