PDA

View Full Version : How to display MYSQL data on index page


Raji
12-19-2003, 11:13 AM
Hello

I am totally new to web programming. I have a MYSQL database with fields date(date, field) Celebration (variable) and slogan(variable). It contains the data for which ecah day is celebrated .
eg.
Date Celebration Slogan
1st Dec. world AIDS day We Care
25th Dec Christmas Merry Christmas

I want take put these 'day celebrations' on my index.html page, two days in advance

eg. on the 23rd Dec., I should display "Merry Christmas"
On the 26th, this should be removed.

Pl. help me to do this.

Thanks

raf
12-19-2003, 11:52 AM
Welcome here.

We need a bit more info. Do you use a serverside language and which (PHP or ASP or JSP ...)? Where exactly do you need help on? (Connectiong to the db, selecting the messages, displaying the messages?

I suppose you use PHP and have your connection open and db selected.
your code will then look like:

$select="SELECT date, celebration, slogan FROM tablename WHERE (TO_DAYS(date) - TO_DAYS(NOW()) BETWEEN 0 and 2)"
$result=mysql_query($select,$link) or die ('Queryproblem');

while ($row=mysql_fetch_array($result)){
echo ($row['date'] . ' ' . $row['celebration'].' '. $row['slogan'] .'<br />');
}

This will print one line for each current or upcomming event (today or max 2 days in the future).
You need to change 'tablename' into your tables name.

Celtboy
12-20-2003, 08:42 AM
just an addition to what raf said,
the part beginning with "SELECT" until the end of the line is good regardless of what language you're using (ASP, PHP, ColdFusion, etc)