Forum Moderators: coopster
I'm trying to get this event listing type script to run. It was a conversion of sorts from a flat file type of setup to this mysql version. I'm really not sure where it's going wrong as I have no access to the server to turn error reporting on. I just thought extra eyes may spot the missing quote or whatever is wrong that I'm not catching.
Anyway, I'm sure it's nasty code but it's more an excercise in learning for me at this point. Any takers?
events.php
==========
include("includes/dbconnect.php");
//begin event check and listing
if(isset($_GET["e"]) &&!empty($_GET["e"])) { //if single event is called[/code]
$e = $_GET["e"];
$result = mysql_query("SELECT * FROM snospree_events WHERE eventid='$eventid' ",$connect);
while($myrow = mysql_fetch_assoc($result)) {//begin loop
//auto-parse URLs
$myrow[eventdesc] = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","<a target=\"_blank\" href=\"$1\">$1</a>", $myrow[eventdesc]);
$myrow[eventurl] = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","<a target=\"_blank\" href=\"$1\">$1</a>", $myrow[eventurl]);
//convert mysql date/time results from YYYY:MM:DD to Weekday, Month Day Year
$myrow[eventdate] = date('l, F jS',strtotime($myrow[eventdate]));
$myrow[eventtime] = date('g:i a',strtotime($myrow[eventtime]));
if($myrow[eventid]) == $e ) {
echo "<h1>$myrow['eventname']</h1>\n";
echo "<table style='width:100%;' cellspacing='0' cellpadding='0'>\n";
echo "<tr>\n";
echo "<td>\n";
// begin single event data here
echo "<span style='color:#666;line-height: 18px;font-size:0.8em;'>Scheduled start: <strong>$myrow['eventdate'] at $myrow['eventtime']</strong>.<br>\n";
if (!empty($myrow[eventurl])) {//url check
echo "<a href='$myrow['eventurl']' target='_blank'></a>$myrow['eventurl']</a><br>\n";
} else {
echo "";
}//end url check
if (!empty($myrow[eventimage])) {//image check
echo "<img src='images/$myrow['eventimage']\" alt='$myrow['eventname']'><br>\n";
} else {
echo "";
}// end image check
echo "<br>\n";
echo "<div style='text-align:right;font-size:0.9em;border-top:1px solid #ccc;line-height:24px;'>[ <a href='events.php'>To Event Listings</a> ]\n";
echo "</div>\n";
}// end loop
} // end single event check
} else { //otherwise, single event wasn't called so begin full schedule listing
echo "<h1>Festival Event Schedule</h1>\n";
echo "<table width='100%' cellspacing='0' cellpadding='0'>\n";
echo "<tr>\n";
echo "<td>\n";
// begin event schedule here
$result = mysql_query("SELECT * FROM snospree_events ORDER BY eventdate ASC",$connect);
// count results
$entries = mysql_num_rows($result);
echo "<br>\n";
echo "\n";
echo "There are <strong>$entries</strong> events scheduled for this years Snospree. For more information on each event, simply click on the event title.<br><br>\n";
//echo "The event listings are temporarily down. Check back often for the most up to date listings of what's going on for Snospree this year!<br><br>\n";
while($myrow = mysql_fetch_assoc($result)) {//begin loop
//auto-parse URLs
$myrow[eventdesc] = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","<a target=\"_blank\" href=\"$1\">$1</a>", $myrow[eventdesc]);
$myrow[eventurl] = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","<a target=\"_blank\" href=\"$1\">$1</a>", $myrow[eventurl]);
//convert mysql date/time results from YYYY:MM:DD to Weekday, Month Day Year
$myrow[eventdate] = date('l, F jS Y',strtotime($myrow[eventdate]));
$myrow[eventtime] = date('g:i a',strtotime($myrow[eventtime]));
if($i % 2 ==0) {
$bgcolor='#efefef'; }
else {
$bgcolor='#ffffff'; }
echo "<tr>
<td valign='middle' style='font-size:0.8em; background-color: $bgcolor; padding: 4px 0 4px 8px;'><a href='?e=$myrow['eventid']'>$myrow['eventname']</a> scheduled start: $myrow['eventtime']</td>
</tr>";
}// end loop
}// end of else
?>
Moose, at first I thought, hey, you're right. In retrospect, no - I was asking for a basic "double-check" not a problem with a specific part of the script. I thought it must have been a simple parse error so I was looking more for the problem being missing quotes, no semicolon to end lines, etc...
Having said that, I'll try and be a bit more concise in the future in regards to how I ask my questions and what code I post up.
Thanks guys. The feedback was appreciated!
[edited by: generic at 11:02 pm (utc) on Feb. 2, 2006]
echo "<a href='$myrow['eventurl']' target='_blank'></a>$myrow['eventurl']</a><br>\n"; or
$myrow[eventurl] ?
In the first there is plenty of room for confusion re: your use of array elements in a single-quoted string. Neater if you assign the array element values to a new variable and then use them. ($eventurl=$myrow['eventurl'])
In the second you assume perhaps too much by not using proper syntax in referring to the array elements. They should be delimited with quotes or apostrophes. ($myrow['eventurl'] instead of $myrow[eventurl])
You should try to get your host to update their installation, as that archaic version of PHP has many known security issues that are still being exploited, and you will have trouble executing anything really fancy because the fancy PHP functions are probably not available. Heck, even 4.x releases are frustratingly outdated now.