Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format font color as a reult of a date/time query

Status
Not open for further replies.

NigeB

Technical User
Nov 29, 2000
53
GB
Is it possible to apply formating font code as a result of a date time?

What I am trying to do is present a list of courses (the result of a query) and Would like to colour all the "am" times Blue and "pm" times Red.

I am just after a few pointers in the right direction.

A snippet of the existing code is below

Many thanks

NigeB

---->
$query = "SELECT courses.course_id, courses.course_date, courses.venue, UNIX_TIMESTAMP(courses.course_date) as unix_date, courses.username, venue.line1, venue.line2, venue.line3
FROM courses
LEFT JOIN venue ON courses.venue = venue.venue
WHERE course_date > curdate()
ORDER BY course_date, venue
LIMIT 3";
$res2 = mysql_query($query);
if ($myrow = mysql_fetch_array($res2)){
do {


printf("<td valign=top align=center class=gentext width=180><b>%s<font color=#336699>%s</font> %s<br>
<br>%s<br><br></b><font size=2>at</font><br><br>%s
<br><br>%s<br><br>%s</td>\n",
date("g:i ",$myrow["unix_date"]), date("a",$myrow["unix_date"]),date("l",$myrow["unix_date"]),date("jS F Y",$myrow["unix_date"]), $myrow["line1"], $myrow["line2"], $myrow["line3"]);


} while ($myrow = mysql_fetch_array($res2));

} else {

echo " ";
}
 
Is there a question about MySQL in there, or just a question about programming?

If the latter, I recommend that you post the question in the form approprirate for your programming language.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Yes the question is how to format a field as a reult of that field, i.e. if it's AM (morning) i would like to format in one way and another way for PM.

Is it possible with mysql?

Regards

NigeB
 
It's certainly possible, but it's a PHP/HTML issue, nothing to do with MySQL.

-----
ALTER world DROP injustice, ADD peace;
 
NigeB:
To agree with TonyGroves....

If you had a problem getting the data out of MySQL, then your question would be appropriate for this forum.

If seems you have a problem formatting the data you successfully retrieve from MySQL. This is a programming-language or output medium question.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I think you misundertand me, sorry, I can get the data out, and format the code - no problem, but can I specify the criteria based on a query result?

The UNIX Timestamp does the formating into AM / PM but based on the result can I then ipose a criteria?

Regards

Nigel
 
My query (listed above) brings back 3 records with numerous fields, one being a time, which is formatted into AM or PM depending on the timestamp value.

What I would like to know is how do I create an output for each record depending on the value of the respective timestamp value, that I can use to create a formatting code for use in the output page.

Regards

NigeB
 
Ok, this is my train of thought

1. create a temporary table and populate with 3 records all with an AM (morning start time)

2. insert a field to be used with the formatting later

3. repeat 1. above for PM

4. insert a different formatting field for the field is blank

5. select the top 3 and hey presto.

My question is now, how do I select based on am or pm in the timestamp?

Thanks

NigeB

 
You *could* do this from mysql but it would be pointlessly hard. You would definately be able to do this more easily in PHP , which is where the change of forum is required :)


______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top