Every day a new Text (thought of a day)
Moderator: General Moderators
Every day a new Text (thought of a day)
Hi
I am just updating/redesigning an old website. I made it into PHP and connected to the mySQL database. Now I would like to make a php script that shows for each day of the month another thought from the database.
I made a new table in the database with ID THOUGHT and DAY
The administration where I add and delete the thoughts is working nice but reading from the database is not working as i want. It shows me all the texts at once.
What i am looking for is a small php code that will read from the databese as follows: If today is a day 6. April 2004 it should show only the THOUGHT under DAY 6. Tomorow than it would be the day 7, and so on...
I just came from JAVA and ASP so I have some problems with PHP althaugh it is a great prog. language...
If you have something peace of code that i can use or some ideas then please let me know.
thnaks
caitanya
I am just updating/redesigning an old website. I made it into PHP and connected to the mySQL database. Now I would like to make a php script that shows for each day of the month another thought from the database.
I made a new table in the database with ID THOUGHT and DAY
The administration where I add and delete the thoughts is working nice but reading from the database is not working as i want. It shows me all the texts at once.
What i am looking for is a small php code that will read from the databese as follows: If today is a day 6. April 2004 it should show only the THOUGHT under DAY 6. Tomorow than it would be the day 7, and so on...
I just came from JAVA and ASP so I have some problems with PHP althaugh it is a great prog. language...
If you have something peace of code that i can use or some ideas then please let me know.
thnaks
caitanya
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You then need to add a WHERE clause to your SELECT statement so that you only retrieve the record you want, you can use two MySQL functions in the SQL, DAYOFMONTH and NOW() to get the current day's number:
http://www.mysql.com/doc/en/Date_and_ti ... tions.html
Mac
Code: Select all
SELECT ID, thought FROM the_table WHERE day = DAYOFMONTH(NOW())Mac
ok here is my old code... it show all the thoughts at once - one under another...
What is missing is some kind of check for the current day...
<?php
function showDaily ($thought, $dates) {
$db = new DB();
$db->query("SELECT * FROM ".DB_PREFIX."_daily" );
while ($thought = $db->next_record()) {
echo "<br><br>$thought[thought]<br>";
}
$db->close();
}
showDaily ($thought, $dates);
?>
thanks for help
caitanya
What is missing is some kind of check for the current day...
<?php
function showDaily ($thought, $dates) {
$db = new DB();
$db->query("SELECT * FROM ".DB_PREFIX."_daily" );
while ($thought = $db->next_record()) {
echo "<br><br>$thought[thought]<br>";
}
$db->close();
}
showDaily ($thought, $dates);
?>
thanks for help
caitanya
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
ok i changed the code to this...
edited: please use the BBCode to format your posts. Easier to to read
and it gives me a parse error in the line 5 meaning:
$db->query("SELECT ID, thought FROM ".DB_PREFIX."_daily" WHERE dates = DAYOFMONTH(NOW()));
what is this DAYOFMONTH(NOW()) function? do i have to make a new table with this name or is it just a sql string...
shouldnt there be a function that first checks what date is today (maybe DAYOFMONTH(NOW())) and then checks which thought has this date in the table DATES.
So my Tables are now ID, THOUGHT, DATES
as i said i am quite bad in php so i need a help on this matter...
thanks
caitanya
edited: please use the BBCode to format your posts. Easier to to read
Code: Select all
function showDaily ($thought, $dates) {
$db = new DB();
$db->query("SELECT ID, thought FROM ".DB_PREFIX."_daily" WHERE dates = DAYOFMONTH(NOW()));
while ($thought = $db->next_record()) {
echo "<br><br>$thought[thought]<br>";
}
$db->close();
}
showDaily ($thought, $dates);$db->query("SELECT ID, thought FROM ".DB_PREFIX."_daily" WHERE dates = DAYOFMONTH(NOW()));
what is this DAYOFMONTH(NOW()) function? do i have to make a new table with this name or is it just a sql string...
shouldnt there be a function that first checks what date is today (maybe DAYOFMONTH(NOW())) and then checks which thought has this date in the table DATES.
So my Tables are now ID, THOUGHT, DATES
as i said i am quite bad in php so i need a help on this matter...
thanks
caitanya
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You need to put the string in quotes otherwise PHP doesn't know what to do with it:caitanya wrote:and it gives me a parse error in the line 5 meaning:Code: Select all
$db->query("SELECT ID, thought FROM ".DB_PREFIX."_daily" WHERE dates = DAYOFMONTH(NOW()));
Code: Select all
$db->query("SELECT ID, thought FROM ".DB_PREFIX."_daily WHERE dates = DAYOFMONTH(NOW())");DAYOFMONTH() and NOW() are functions within MySQL - the link I posted in my first post has information on both.caitanya wrote:what is this DAYOFMONTH(NOW()) function? do i have to make a new table with this name or is it just a sql string...
Table or field? I think you mean field. Previously you said that there was a field called day containing day numbers and that's what my previous code is based on - if that is now a specific date (i.e you have 366 thoughts) AND stored in a MySQL DATE type column, then you can change the SQL to:caitanya wrote:shouldnt there be a function that first checks what date is today (maybe DAYOFMONTH(NOW())) and then checks which thought has this date in the table DATES. So my Tables are now ID, THOUGHT, DATES
Code: Select all
SELECT ID, thought FROM the_table WHERE dates = NOW()ok thanks now it works... i hope.
which date does it take? mine or the one from server?
cause now it shows me correctly the daily thought nr. 6 for the 6.April 2004 and if i change the date on my machine it still shows the thought nr. 6...
anyway i'll see this tomorow...
thanks this forum is grat
caitanya
which date does it take? mine or the one from server?
cause now it shows me correctly the daily thought nr. 6 for the 6.April 2004 and if i change the date on my machine it still shows the thought nr. 6...
anyway i'll see this tomorow...
thanks this forum is grat
caitanya