I'm having trouble with the else/if statement below (I get a parse error). I'm trying to echo a statement if nothing is pulled up in the query. Any help would be greatly appreciated.
<?
// Set the database access information as constants.
DEFINE ('DB_USER', '______');
DEFINE ('DB_PASSWORD', '_____');
DEFINE ('DB_HOST', '127.0.0.1');
DEFINE ('DB_NAME', 'wordriot_org_-_bbs');
// Make the connnection and then select the database.
$dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db (DB_NAME);
$query="SELECT * FROM web_readings WHERE state = 'Connecticut' ORDER BY month AND date";
$result=mysql_query($query);
$num=mysql_num_rows($result) or exit(mysql_error());
mysql_close();
$i=0;
if ($num==0) {
echo "No readings for this state available.";
} else ($i < $num) {
$comments = mysql_result($result,$i,"comments");
$event_title = mysql_result($result,$i,"event_title");
$venue = mysql_result($result,$i,"venue");
$description = mysql_result($result,$i,"description");
$month = mysql_result($result,$i,"month");
$date = mysql_result($result,$i,"date");
$year = mysql_result($result,$i,"year");
$time = mysql_result($result,$i,"time");
$address = mysql_result($result,$i,"address");
$city = mysql_result($result,$i,"city");
$state = mysql_result($result,$i,"state");
$contact_name = mysql_result($result,$i,"contact_name");
$contact_email = mysql_result($result,$i,"contact_email");
$website = mysql_result($result,$i,"website");
echo "<b>$month $date, $year</b><br><br><i>$event_title</i><br>$venue<br>$time<br><br>$address<br>$city, $state<br><br>$description<br><br>CONTACT INFORMATION<br>$contact_name, $contact_email<br><a href=http://www.htmlforums.com/archive/index.php/$website>$website</a><br><br><br>";
++$i;
}
?>Originally posted by crazyjackie
} else ($i < $num) {
should be
} else {
while ($i < $num) {
...
}
}
and i think that your mysql_close is too soon in the script since you have mysql_result after!thanks--
unfortunately, if i don't have any rows posted for a specified state (like Connecticut) all the html & php after that state gets cut off. right now i have info. filled in, but it looks really awful: <!-- m --><a class="postlink" href="http://readings.wordriot.orgalso">http://readings.wordriot.orgalso</a><!-- m -->
$result=mysql_query($query);
$num=mysql_num_rows($result) or exit(mysql_error());
should be
$result=mysql_query($query) or die(mysql_error());
$num=mysql_num_rows($result);
you can't error out on a num_rows function, it is the query that needs it.thanks, scoutt! that fixed it.
<?
// Set the database access information as constants.
DEFINE ('DB_USER', '______');
DEFINE ('DB_PASSWORD', '_____');
DEFINE ('DB_HOST', '127.0.0.1');
DEFINE ('DB_NAME', 'wordriot_org_-_bbs');
// Make the connnection and then select the database.
$dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db (DB_NAME);
$query="SELECT * FROM web_readings WHERE state = 'Connecticut' ORDER BY month AND date";
$result=mysql_query($query);
$num=mysql_num_rows($result) or exit(mysql_error());
mysql_close();
$i=0;
if ($num==0) {
echo "No readings for this state available.";
} else ($i < $num) {
$comments = mysql_result($result,$i,"comments");
$event_title = mysql_result($result,$i,"event_title");
$venue = mysql_result($result,$i,"venue");
$description = mysql_result($result,$i,"description");
$month = mysql_result($result,$i,"month");
$date = mysql_result($result,$i,"date");
$year = mysql_result($result,$i,"year");
$time = mysql_result($result,$i,"time");
$address = mysql_result($result,$i,"address");
$city = mysql_result($result,$i,"city");
$state = mysql_result($result,$i,"state");
$contact_name = mysql_result($result,$i,"contact_name");
$contact_email = mysql_result($result,$i,"contact_email");
$website = mysql_result($result,$i,"website");
echo "<b>$month $date, $year</b><br><br><i>$event_title</i><br>$venue<br>$time<br><br>$address<br>$city, $state<br><br>$description<br><br>CONTACT INFORMATION<br>$contact_name, $contact_email<br><a href=http://www.htmlforums.com/archive/index.php/$website>$website</a><br><br><br>";
++$i;
}
?>Originally posted by crazyjackie
} else ($i < $num) {
should be
} else {
while ($i < $num) {
...
}
}
and i think that your mysql_close is too soon in the script since you have mysql_result after!thanks--
unfortunately, if i don't have any rows posted for a specified state (like Connecticut) all the html & php after that state gets cut off. right now i have info. filled in, but it looks really awful: <!-- m --><a class="postlink" href="http://readings.wordriot.orgalso">http://readings.wordriot.orgalso</a><!-- m -->
$result=mysql_query($query);
$num=mysql_num_rows($result) or exit(mysql_error());
should be
$result=mysql_query($query) or die(mysql_error());
$num=mysql_num_rows($result);
you can't error out on a num_rows function, it is the query that needs it.thanks, scoutt! that fixed it.