Hello.
I'm running a query on my database, and what I want to happen is that "if" the query fails or does not return anything, then it sets a variable, which is later read, with a type of "system" message that I want.
Problem is, I've tried using
if(!$result){
//set the variable
}
// I've also tried
if($result != 'true'){
// set the variable
}
What seems to happen is that if I use the first example, then the variables don't get set. If I use the second example, I get the variables set, and everything works fine, except that where I do have data in the database, it won't show it.
Here's some code:
global $dbc;
$query = "SELECT * FROM `main_news` ORDER BY `id` DESC LIMIT 3";
$result = mysql_query($query, $dbc);
if($result != 'true'){
$news = '<h2>News</h2>'."\n".
'<div class="news-wrap">'."\n".
'<p class="nItem">No news items were found.</p>'."\n".
'</div>'."\n";
}
else{
while($display = mysql_fetch_array($result)){
$id = $display['id'];
$title = $display['Title'];
$short = $display['Intro'];
$news = '<div class="news-wrap">'."\n".
'<h2>'.$title.'</h2>'."\n".
'<p class="nItem">'.$short.'<br />'."\n".
'<a href="http://www.winfieldvfd.org/read.php?cat=news&id='.$id.'">Read More...</a></p>'."\n".
'</div>'."\n";
}
}
Thanks for any help you guys can give me.
~Brett