Checking MySQL for entry?
Posted: Tue Mar 22, 2011 3:02 pm
Hey ya guys. I'm still learning php and sql but I'm starting to get the hang of it I think.
This website CMS I'm working on is starting to get complicated and I wanted to add a new feature to the whole site. Firstly I should say that there is a free and a premium site to site because of the art that is being sold by artist (well at least that is what I'm going for), and I wanted to have a single page or panel that had the updates on it. Like new stock video, or new print, ect ect. So I made a table in sql but not I'm stuck on some logic problems with how that is updated because some days will not have some types of content versus other kinds, and I don't want to do it manually (who would with these tools in front of us), but rather it gets updated when I use the posting admin panel or an aritist dose.
Anyway, here is the real question. In php how do I check a table for a date from the database? Like an if() statement?
example of what I was thinking:(not code correct at all)
Not sure if that would work. Also I want to add a prepost to this. Like say I wanted to add some new stock art or something for sale, but I wanted it to post on the 1st of April, (and the system can account for this with just a DATETIME check versus current time in php if it should show on the site ;p), but not sure how I would check a datetime from php into mysql, if that makes since. I can get the post time from another table easily enough in the same page with doing this, in the format like "2011-01-04 08:53:00" and then I do know how to explode it and stuff ;p anyway, hope to hear from you guys.
This website CMS I'm working on is starting to get complicated and I wanted to add a new feature to the whole site. Firstly I should say that there is a free and a premium site to site because of the art that is being sold by artist (well at least that is what I'm going for), and I wanted to have a single page or panel that had the updates on it. Like new stock video, or new print, ect ect. So I made a table in sql but not I'm stuck on some logic problems with how that is updated because some days will not have some types of content versus other kinds, and I don't want to do it manually (who would with these tools in front of us), but rather it gets updated when I use the posting admin panel or an aritist dose.
Anyway, here is the real question. In php how do I check a table for a date from the database? Like an if() statement?
example of what I was thinking:(not code correct at all)
Code: Select all
<?
mysql_connect();
mysql_select_db();
//check if today has an entry
$sql = "SELECT * FROM table WHERE DATETIME = TODAY LIMIT 0,1";
$sql_result = mysql_query($sql);
if($sql_result){
//UPDATE ENTRY
}else{
//INSERT NEW ENTRY FOR TODAY INTO TABLE
}
?>