Solved

make a timtable in html from information from mysql

Posted on 2009-04-03
6
485 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn how to dynamically set the form action using jQuery.
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now