RysChwith
11-27-2004, 07:43 PM
Here is undoubtedly another one to blame on the turkey.
The following code is supposed to query a database and write the results into a page. I know the query works, because I've tested it directly. It returns three records. However, the page absolutely refuses to go into the while loop, despite the fact that I copied and pasted that code from a functioning page. It's probably something stupid, but I'm at a loss to see it.
<?php
$db_error = "<p>Event information is currently unavailable. Please try back later.</p>\n";
$today = date( 'Y-m-d' );
if( $dbConn = @mysql_connect( '*****', '*****', '*****' ) )
{
if( @mysql_select_db( '*****' ) )
{
$query = "SELECT name, url, startdate, enddate FROM Events WHERE 'group' = 002";
print "<!-- " . $query . " -->\n";
if( $results = mysql_query( $query ) )
{
$count = 0;
print "<!-- Results are: " . $results . " -->\n";
while( $row = mysql_fetch_array( $results ) )
{
print "<!-- Printing row. -->\n";
print "<p><em>" . $row[ 'startdate' ];
if( $row[ 'enddate' ] > $row[ 'startdate' ] )
{
print " - " . $row[ 'enddate' ];
}
print ":</em> <a href = \"";
if( $row[ 'url' ] != "" )
{
print $row[ 'url' ];
}
else
{
print "events/index.html";
}
print "\">" . $row[ 'name' ] . "</a></p>\n";
$count++;
}
print "<!-- After while loop. -->\n";
if( $count < 1 )
{
print "<p>There are no events currently scheduled.</p>\n";
}
}
else
{
print $db_error . "<p>Query failed because of: ";
print mysql_error() . "</p>";
}
}
else
{
print $db_error . "<p>DB select failed.</p>";
}
}
else
{
print $db_error . "<p>DB connection failed.</p>";
}
?>
(Note that the actual code contains server information rather than asterisks, but I didn't feel like putting it out in a public forum. I'm sure you'll all understand.)
The HTML comments I've thrown in for testing purposes produce the following results:
<!-- SELECT name, url, startdate, enddate FROM Events WHERE 'group' = '002' -->
<!-- Results are: Resource id #2 -->
<!-- After while loop. -->
Anyone who wants to see the results in situ can check here (http://www.stormsport.org/test/index.php) .
Rys
The following code is supposed to query a database and write the results into a page. I know the query works, because I've tested it directly. It returns three records. However, the page absolutely refuses to go into the while loop, despite the fact that I copied and pasted that code from a functioning page. It's probably something stupid, but I'm at a loss to see it.
<?php
$db_error = "<p>Event information is currently unavailable. Please try back later.</p>\n";
$today = date( 'Y-m-d' );
if( $dbConn = @mysql_connect( '*****', '*****', '*****' ) )
{
if( @mysql_select_db( '*****' ) )
{
$query = "SELECT name, url, startdate, enddate FROM Events WHERE 'group' = 002";
print "<!-- " . $query . " -->\n";
if( $results = mysql_query( $query ) )
{
$count = 0;
print "<!-- Results are: " . $results . " -->\n";
while( $row = mysql_fetch_array( $results ) )
{
print "<!-- Printing row. -->\n";
print "<p><em>" . $row[ 'startdate' ];
if( $row[ 'enddate' ] > $row[ 'startdate' ] )
{
print " - " . $row[ 'enddate' ];
}
print ":</em> <a href = \"";
if( $row[ 'url' ] != "" )
{
print $row[ 'url' ];
}
else
{
print "events/index.html";
}
print "\">" . $row[ 'name' ] . "</a></p>\n";
$count++;
}
print "<!-- After while loop. -->\n";
if( $count < 1 )
{
print "<p>There are no events currently scheduled.</p>\n";
}
}
else
{
print $db_error . "<p>Query failed because of: ";
print mysql_error() . "</p>";
}
}
else
{
print $db_error . "<p>DB select failed.</p>";
}
}
else
{
print $db_error . "<p>DB connection failed.</p>";
}
?>
(Note that the actual code contains server information rather than asterisks, but I didn't feel like putting it out in a public forum. I'm sure you'll all understand.)
The HTML comments I've thrown in for testing purposes produce the following results:
<!-- SELECT name, url, startdate, enddate FROM Events WHERE 'group' = '002' -->
<!-- Results are: Resource id #2 -->
<!-- After while loop. -->
Anyone who wants to see the results in situ can check here (http://www.stormsport.org/test/index.php) .
Rys