0

I've got a simple PHP page with a list of events that are taking place at certain times on certain days, and this is my code:

<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","root","PASSWORD"); 
//select which database you want to edit
mysql_select_db("events"); 
//select the table
$result = mysql_query("select * from weekevent order by eventdate LIMIT 20");
//grab all the content
while($r=mysql_fetch_array($result));
{	
   //the format is $variable = $r["nameofmysqlcolumn"];
   //modify these to match your mysql table columns
   $event=$r["event"];
   $eventdate=$r["eventdate"];
echo "<tr><td><b>$event</b></td><td>showing on $eventdate</td>";
}
	// assumes that you have connected successfully to your database using mysql_connect and mysql_select_db
$result = mysql_query("select eventdate from events"); // runs a query in your database
if($result)
{
   $row = mysql_fetch_assoc($result); // gets the first result set row from the database for the query
   $databaseDate = $row["eventdate"]; // that is, reference the column name of your table
   $formattedDate = date("Y-m-d G:i:s", strtotime($databaseDate)); // this puts the date into the format "yyyy-mm-dd h24:mm:ss"
}
?>

yet I get this error:

Notice: Undefined variable: formattedDate in C:\www\vhosts\eventsweb\eventsweekly.php on line 20

What should I do so it shows events properly?

2
Contributors
10
Replies
12
Views
7 Years
Discussion Span
Last Post by CFROG
0

Have you tried this?

$formattedDate = date("Y-m-d G:i:s", $databaseDate);

I could be completely wrong but it would seem as though you wouldn't need strtotime() .
Correct me if I'm wrong.
You could also use

$databaseDate = strtotime('your preferred date format');
0

Where do I put it in the code?

<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","root","PASSWORD"); 
//select which database you want to edit
mysql_select_db("events"); 
//select the table
$result = mysql_query("select * from weekevent order by eventdate LIMIT 20");
//grab all the content
while($r=mysql_fetch_array($result));
{	
   //the format is $variable = $r["nameofmysqlcolumn"];
   //modify these to match your mysql table columns
   $event=$r["event"];
   $eventdate=$r["eventdate"];
echo "<tr><td><b>$event</b></td><td>showing on $eventdate</td>";
}
	// assumes that you have connected successfully to your database using mysql_connect and mysql_select_db
$result = mysql_query("select eventdate from events"); // runs a query in your database
if($result)
{
   $row = mysql_fetch_assoc($result); // gets the first result set row from the database for the query
   $databaseDate = $row["eventdate"]; // that is, reference the column name of your table
   $formattedDate = date("Y-m-d G:i:s", strtotime($databaseDate)); // this puts the date into the format "yyyy-mm-dd h24:mm:ss"
}
?>
0

Replace line 24 with this $formattedDate = date("Y-m-d G:i:s", $databaseDate);

Edited by CFROG: n/a

0
<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","root","PASSWORD"); 
//select which database you want to edit
mysql_select_db("events"); 
//select the table
$result = mysql_query("select * from weekevent order by eventdate LIMIT 20");
//grab all the content
while($r=mysql_fetch_array($result));
{	
   //the format is $variable = $r["nameofmysqlcolumn"];
   //modify these to match your mysql table columns
   $event=$r["event"];
   $eventdate=$r["eventdate"];
echo "<tr><td><b>$event</b></td><td>showing on $eventdate</td>";
}
	// assumes that you have connected successfully to your database using mysql_connect and mysql_select_db
$result = mysql_query("select eventdate from events"); // runs a query in your database
if($result)
{
   $row = mysql_fetch_assoc($result); // gets the first result set row from the database for the query
   $databaseDate = $row["eventdate"]; // that is, reference the column name of your table
$formattedDate = date("Y-m-d G:i:s", $databaseDate);
}
?>

OK, I've done that but now get the following error message:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource inin C:\www\vhosts\eventsweb\eventsweekly.php in line 10

what do I do next?

0

Sounds like something is wrong with your query

$result = mysql_query("select * from weekevent order by eventdate LIMIT 20");

Make sure 'weekevent ' is the proper table name and 'eventdate' is the proper column name. They are case sensitive and must match the db exactly.

0

I have to head out in a few so you might also want to write the query as

$result = mysql_query("select * from weekevent order by eventdate LIMIT 20") or die(mysql_error());

That will give you an idea of what's wrong with the query. You can also try to echo the query ...

echo $result; die;
0

Is it giving you an error? Describe what you mean when you say data isn't being extracted.

0

$event and $eventdate variables seem to be empty. Need to find out why that is. Try this out:

$result = mysql_query("select * from weekevent order by eventdate LIMIT 20");
$count = mysql_num_rows($result);
echo $count; die;

If you get a blank screen your query is not returning any results which I'm guessing is exactly what is happening. echo $result; die; can help you try to narrow down what's wrong with it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.