Jump to content

Throw Error Message


datoshway

Recommended Posts

Can someone help me add a else statement to throw a error if no results are found?

 

Here is my query.

<?php require "_controller.php";

db_connect();
db_select();

$strQuery				= "SELECT * FROM tblXXX GROUP BY intXXX";
$queryGetNews			= db_query($strQuery);

?>

   <?php
				if (db_num_rows($queryGetNews) > 0) {

					while ($objRow			= db_fetch_object($queryGetArticle)) {

					$intXXX	= intval($objRow->intID);
                        $txtXXX		= strip_tags(stripslashes($objRow->txtXXXe));
						?>
         
     <?php echo $txtXXX; ?>

       <?php
					}
					db_free_result($queryGetNews);
				}

			?>

 

Link to comment
Share on other sites

No go, I'm getting a syntax error.  This is what it looks like after what you sent me.

 

  <?php
if (db_num_rows($queryGetNews) > 0) {
while ($objRow= db_fetch_object($queryGetArticle)) {

		$intRaceID	= intval($objRow->intID);
                        $txtUpdate		= strip_tags(stripslashes($objRow->txtUpdate));
                        $dtEntered	= stripslashes($objRow->dtEntered);
                        ?>
                   <?php echo $txtUpdate; ?>
<?php
    echo date("g:i A", strtotime($dtEntered));
?>
	<?php  
} else {
//throw error message
echo "error has occured or no rows returned<br/>".mysql_error();
}?>

Link to comment
Share on other sites

you don't need to open and close the <?php ?> tags so often, you only need to open at the start and close after the end of the PHP code.

 

The syntax error you're getting would be because you are missing a set of closing brackets for the while loop

  <?php
if (db_num_rows($queryGetNews) > 0) {
while ($objRow= db_fetch_object($queryGetArticle)) { //open while loop
$intRaceID = intval($objRow->intID);
                        $txtUpdate = strip_tags(stripslashes($objRow->txtUpdate));
                        $dtEntered = stripslashes($objRow->dtEntered);
   
     echo $txtUpdate;
    echo date("g:i A", strtotime($dtEntered));
} //close while loop

} else { //close IF and add else statement
//throw error message
echo "error has occured or no rows returned<br/>".mysql_error();
}?>

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.