Solved

make a timtable in html from information from mysql

Posted on 2009-04-03
6
534 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

627 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