Solved

make a timtable in html from information from mysql

Posted on 2009-04-03
6
498 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
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!

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Healthcheck 2 85
Animated .jpg? 13 61
update joined tables 2 31
Making register page log you in after registration is complete. 2 14
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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 look for a specific file type in a local or remote server directory using PHP.

895 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

12 Experts available now in Live!

Get 1:1 Help Now