Gates_of_Janus Posted July 19, 2007 Share Posted July 19, 2007 I’m still in the process of learning PHP and MySQL so this is likely far more straightforward than I’m trying to make it out to be in my head... Basically I’m planning to set up a MySQL database that has information that I want displayed on a certain date. Specifically this is for an RPG game site in which I would like to be able to display the game date, time, moon phase, ect. – information that changes daily but is all calculated out vastly ahead of time. As it currently is it’s a static HTML page that is supposed to be updated everyday...that of course doesn’t always happen which is why I am looking to ‘automate’ the process by laying out all the information ahead of time in a database and setting up the site to display the correct line of information on the correct realtime date. So say on 7/19/07 realtime I would want it to say that it was 9/27/01, 6 AM, First Quarter Moon then on 7/20/07 realtime I’d want it to say that it was 9/27/01, 6:08 AM, First Quarter Moon and so on. What I’m having a problem with is figuring out how to on the PHP side tell it to display a certain set of MySQL fields on a specific date. I keep looking at doing a modification of a birthday script and at event planners, but I’m wondering if there’s a more straightforward way that I’m missing. Any suggestions that might point me in the right direction would be much appreciated. Thanks, Amanda Quote Link to comment https://forums.phpfreaks.com/topic/60727-solved-displaying-specific-database-content-on-a-specific-date/ Share on other sites More sharing options...
Gates_of_Janus Posted September 25, 2007 Author Share Posted September 25, 2007 I'm still working on trying to display particular content on a specific date but am having some issues. I have a database (date) set up with the information I want displayed. One of those columns is 'timepst'. The dates in the 'trudate' column are formated like '2007-9-25' and I'm not sure if that is perhaps incorrect for the way I'm trying to access the data because I haven't been able to get results with either CURDATE() or NOW(). Below is one of the test scripts I have been working with. I'm not getting any errors from it, but nor is it displaying any data - only a white screen and that's the same thing I'm getting from the other versions of this script I've tried which is why I'm not sure if I have the date info formatted correctly. Here's a simple version of the script: <?php $dbhost = 'host'; $dbuser = 'login'; $dbpass = 'pass'; $conn= mysql_connect("$dbhost" ,"$dbuser" ,"$dbpass") ; if(!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("date")) { echo " Unable to select Date Database: " . mysql_error() ; exit; } $query = mysql_query("SELECT timepst FROM date WHERE trudate=CURDATE()") or die(mysql_error()); $row = mysql_fetch_assoc($query) or die(mysql_error()); $time = $row['timepst']; echo $time ?> Any suggestions as to why this is returning a blank screen would be immensely appreciated. Thanks, Amanda Quote Link to comment https://forums.phpfreaks.com/topic/60727-solved-displaying-specific-database-content-on-a-specific-date/#findComment-355324 Share on other sites More sharing options...
darkfreaks Posted September 25, 2007 Share Posted September 25, 2007 hey amanda i noticed some bad coding try the following code : <?php $dbhost = 'host'; $dbuser = 'login'; $dbpass = 'pass'; $conn= mysql_connect("$dbhost" ,"$dbuser" ,"$dbpass") ; if($conn=="false") { echo "Unable to connect to DB: " . mysql_error(); exit; } if (mysql_select_db("date")=="false") { echo " Unable to select Date Database: " . mysql_error() ; exit; } $query = mysql_query("SELECT timepst FROM date WHERE trudate=CURDATE()") or die(mysql_error()); $row = mysql_num_rows($query) or die(mysql_error()); $time = $row['timepst']; echo ($time); ?> Quote Link to comment https://forums.phpfreaks.com/topic/60727-solved-displaying-specific-database-content-on-a-specific-date/#findComment-355326 Share on other sites More sharing options...
darkfreaks Posted September 25, 2007 Share Posted September 25, 2007 Also let me know if it works or not. Quote Link to comment https://forums.phpfreaks.com/topic/60727-solved-displaying-specific-database-content-on-a-specific-date/#findComment-355337 Share on other sites More sharing options...
Gates_of_Janus Posted September 25, 2007 Author Share Posted September 25, 2007 Thank you very much for your reply and syntax corrections. I'm still getting the hang of PHP - could you perhaps tell me a little bit about how this portion of the login works: $conn= mysql_connect("$dbhost" ,"$dbuser" ,"$dbpass") ; if($conn=="false") { echo "Unable to connect to DB: " . mysql_error(); exit; } if (mysql_select_db("date")=="false") { echo " Unable to select Date Database: " . mysql_error() ; exit; } Now I'm getting the message 'Unable to select Date Database:' but I know my login info is correct because I can access that database with other scripts. Is 'mysql_select_db("date")' the portion that is telling it which database to access? Thanks again, Amanda Quote Link to comment https://forums.phpfreaks.com/topic/60727-solved-displaying-specific-database-content-on-a-specific-date/#findComment-355339 Share on other sites More sharing options...
darkfreaks Posted September 25, 2007 Share Posted September 25, 2007 if mysql_select_db "date" equals equals false echo "error:" .mysql_error(); you could always change it to if(!mysql_select_db()) { i think this would get solved faster over yahoo i added you. and i think your rpg idea is cool also try added under your if statement else if (mysql_select_db(date)=="true") { $sql="INSERT INTO mytable VALUES (variables)"; } Quote Link to comment https://forums.phpfreaks.com/topic/60727-solved-displaying-specific-database-content-on-a-specific-date/#findComment-355340 Share on other sites More sharing options...
darkfreaks Posted September 25, 2007 Share Posted September 25, 2007 Try: <?php $dbhost = 'host'; $dbuser = 'login'; $dbpass = 'pass'; $conn= mysql_connect("$dbhost" ,"$dbuser" ,"$dbpass") ; if($conn=="false") { echo "Unable to connect to DB: " . mysql_error(); exit; } if (mysql_select_db("date")=="false") { echo " Unable to select Date Database: " . mysql_error() ; exit; } else if (mysql_select_db("date")=="true") { $query = mysql_query("SELECT timepst FROM date WHERE trudate=CURDATE()") or die(mysql_error()); } $row = mysql_num_rows($query) or die(mysql_error()); $time = $row['timepst']; echo ($time); ?> Quote Link to comment https://forums.phpfreaks.com/topic/60727-solved-displaying-specific-database-content-on-a-specific-date/#findComment-355350 Share on other sites More sharing options...
darkfreaks Posted September 26, 2007 Share Posted September 26, 2007 let me know if you get any errors ??? Quote Link to comment https://forums.phpfreaks.com/topic/60727-solved-displaying-specific-database-content-on-a-specific-date/#findComment-355357 Share on other sites More sharing options...
Gates_of_Janus Posted September 26, 2007 Author Share Posted September 26, 2007 With that it makes it past the database connect but gets caught up on the selection of the database. With the new code it's echoing the error: 'Unable to select Date Database:' Is it bad practice to use: '$dbhost = 'host'; $dbuser = 'login'; $dbpass = 'pass'; $conn= mysql_connect("$dbhost" ,"$dbuser" ,"$dbpass") ; mysql_select_db("date") or die("Could not select database"); I don't have any issues logging in with that, but obviously I don't want to use it if it's not a good way to go about it. Thanks, Amanda Quote Link to comment https://forums.phpfreaks.com/topic/60727-solved-displaying-specific-database-content-on-a-specific-date/#findComment-355437 Share on other sites More sharing options...
darkfreaks Posted September 26, 2007 Share Posted September 26, 2007 it could not find Date because it wasnt connected first hehe <?php $dbhost = 'host'; $dbuser = 'login'; $dbpass = 'pass'; $conn= mysql_connect("$dbhost" ,"$dbuser" ,"$dbpass") ; if($conn=="false") { echo "Unable to connect to DB: " . mysql_error(); exit; } if (mysql_select_db("date",$conn)=="false") { echo " Unable to select Date Database: " . mysql_error() ; exit; } else if (mysql_select_db("date",$conn)=="true") { $query = mysql_query("SELECT timepst FROM date WHERE trudate=CURDATE()") or die(mysql_error()); } $row = mysql_num_rows($query) or die(mysql_error()); $time = $row['timepst']; echo ($time); ?> ) Quote Link to comment https://forums.phpfreaks.com/topic/60727-solved-displaying-specific-database-content-on-a-specific-date/#findComment-355442 Share on other sites More sharing options...
darkfreaks Posted September 26, 2007 Share Posted September 26, 2007 <?php $dbhost = 'host'; $dbuser = 'login'; $dbpass = 'pass'; $conn= mysql_connect("$dbhost" ,"$dbuser" ,"$dbpass") ; if($conn=="false") { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("date",$conn)) { echo " Unable to select Date Database: " . mysql_error() ; exit; } else if (mysql_select_db("date",$conn)=="true") { $query = mysql_query("SELECT timepst FROM date WHERE trudate=CURDATE()") or die(mysql_error()); $row = mysql_num_rows($query) or die(mysql_error()); $time = $row['timepst']; echo $time; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/60727-solved-displaying-specific-database-content-on-a-specific-date/#findComment-355835 Share on other sites More sharing options...
Gates_of_Janus Posted September 26, 2007 Author Share Posted September 26, 2007 Thank you so much for all your assistance. No more blank pages. It's returning the correct values with: $conn= mysql_connect("$dbhost" ,"$dbuser" ,"$dbpass") ; if($conn=="false") { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("gamedate",$conn)) { echo " Unable to select Date Database: " . mysql_error() ; exit; } $query = mysql_query("SELECT * FROM sheet1 WHERE trudate=CURDATE()") or die(mysql_error()); $row = mysql_fetch_assoc($query) or die(mysql_error()); echo $row["timepst"] ?> The actual larger script is working now as well. Thanks again, Amanda Quote Link to comment https://forums.phpfreaks.com/topic/60727-solved-displaying-specific-database-content-on-a-specific-date/#findComment-355942 Share on other sites More sharing options...
darkfreaks Posted September 26, 2007 Share Posted September 26, 2007 yeah its easier just to echo the row then to put the row inside a variable i should have brought that up earlier! and if mysql_fetch_assoc works better than mysql_num_rows go fir it! Quote Link to comment https://forums.phpfreaks.com/topic/60727-solved-displaying-specific-database-content-on-a-specific-date/#findComment-355947 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.