Jump to content

[SOLVED] Displaying Specific Database Content on a Specific Date


Gates_of_Janus

Recommended Posts

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

Link to comment
Share on other sites

  • 2 months later...

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

Link to comment
Share on other sites

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); 

?> 



Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)"; }

Link to comment
Share on other sites

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); 

?> 








Link to comment
Share on other sites

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

Link to comment
Share on other sites

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); 

?> 
) 

Link to comment
Share on other sites

<?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; 
}

?> 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.