Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have the table lecture_table shown below
------------------------------------------------------------------------------------
| lecture_name| lecturer_name | class | day| start | end |
|-------------+------------------+-----------------------------+----+------ +------|
| Math I | Ammar Al-Essa | Computer Engineering Class 1| 0 | 8.5 | 10.5 |
------------------------------------------------------------------------------------
i try to

search by lecture startup time and i want to type lecture time such as"08:30 AM" instead of 8.5 then this value converted to 8.5 like in the table above.
the result i want to be shown like "08:30 AM" for start time and "10.30 AM" for end time.
as you can see the day is also an integer number and i already convert the entry from sundry to 0 in database to compare it "Sunday" not as "0".

the final result should be like this
-----------------------------------------------------------------------------------------
| lecture_name| lecturer_name| class | day |start | end |
|-------------+----------------+-----------------------------+-------+------ +----------|
| Math I | Ammar Al-Essa| Computer Engineering Class 1|Sunday |08:30 Am |10:30 AM|
-----------------------------------------------------------------------------------------

one last thing i used this code to covert days but it didn't work when i used it with times

$raw_results = mysql_query("SELECT lecture_name,
lecturer_name,
class,
start,
end,
CASE day
WHEN 0 THEN 'Sunday'
WHEN 1 THEN 'Monday'
WHEN 2 THEN 'Tuesday'
WHEN 3 THEN 'Wednesday'
WHEN 4 THEN 'Thursday'
WHEN 5 THEN 'Friday'
WHEN 6 THEN 'Saturday'
ELSE 'Unknown'
END AS x
FROM lecture_table WHERE (`lecture_name` LIKE '%".$name."%')") or die(mysql_error());

any support will be highly appreciated
Posted

1 solution

First lets see about the start and end field. While creating the table, set the datatype of these two fields as TIME. Now, while you insert into the database insert in the format HH:MM:SS. While you retrieve also, you will get in the same format. If you want to format it in someother way, you can do so using php.

Now coming to the day field, change its datatype to DATE and store the date in the database. After retrieving the date in the php, format it and display the Day like,

PHP
echo date("l",$date);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900