ballhogjoni Posted August 11, 2008 Share Posted August 11, 2008 I have a while loop that loops through the resource of the mysql query and I am testing whether there are results or not, but for some reason this doesn't work. The code should echo No results were found becasue there are no results in the db right now. If I print_r() the $rResult variable I get the resource id #5 error. I was looking to see if you can help me or give me some advice. Here is my code: <?php $oDB = new FACSDatabase(); $rResult = $oDB->Select('Articles', '*'); while ( $row = mysql_fetch_array( $rResult ) ) { if( $row['title'] == '' || $row['title'] == NULL ){ echo '<tr><td colspan="2">No results were found</td></tr>'; }else{ echo '<tr><td>'.$row['title'].'</td><td><a style="font-size:10px;" href="?id='.$row['article_id'].'&action=edit">[edit]</a></td></tr>'; } } ?> Select() in class FACSDatabase <?php function Select($sTable=NULL,$a_sData=NULL,$sWhere=NULL,$sGroupBy=NULL){ if( is_array( $a_sData ) ){ $sColumns = ""; if( sizeof( $a_sData ) > 1 ){ foreach( $a_sData as $data => $value ){ $sColumns .= $value.','; } $a_sData = trim( $sColumns, ',' ); }else{ foreach( $a_sData as $data => $value ){ $sColumns .= $value; } $a_sData = $sColumns; } $sql = "SELECT ".$a_sData." FROM ".$sTable." ".$sWhere." ".$sGroupBy; $aResult = mysql_query($sql) or die( "MySql Error: ".mysql_error() ); }else{ $sql = "SELECT ".$a_sData." FROM ".$sTable." ".$sWhere." ".$sGroupBy; $aResult = mysql_query($sql) or die( "MySql Error: ".mysql_error() ); } return $aResult; } ?> Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 11, 2008 Share Posted August 11, 2008 Do the echo here and see if it is any different: <?php $oDB = new FACSDatabase(); $rResult = $oDB->Select('Articles', '*'); while ( $row = mysql_fetch_array( $rResult ) ) { print_r($row); if( $row['title'] == '' || $row['title'] == NULL ){ echo '<tr><td colspan="2">No results were found</td></tr>'; }else{ echo '<tr><td>'.$row['title'].'</td><td><a style="font-size:10px;" href="?id='.$row['article_id'].'&action=edit">[edit]</a></td></tr>'; } } ?> Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted August 11, 2008 Author Share Posted August 11, 2008 nothing echoes inside the loop so that tells me the condition isn't right. Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 11, 2008 Share Posted August 11, 2008 Sorry, I didn't see where your "No results" echo was, earlier. It is never getting to that condition because there are no rows for it to ever start the while loop. Try this: <?php $oDB = new FACSDatabase(); $rResult = $oDB->Select('Articles', '*'); if( mysql_num_rows($rResult) echo '<tr><td colspan="2">No results were found</td></tr>'; while ( $row = mysql_fetch_array( $rResult ) ) { echo '<tr><td>'.$row['title'].'</td><td><a style="font-size:10px;" href="?id='.$row['article_id'].'&action=edit">[edit]</a></td></tr>'; } ?> Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted August 11, 2008 Author Share Posted August 11, 2008 thx that did it! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.