Jump to content

SELECT COUNT (*)


tomfmason

Recommended Posts

This should be a rather simple fix. I am trying to put the number of matches from a search into a variable
like this


[code=php:0]<?php
include('db.php');
$sql= sprintf("SELECT COUNT(*) AS message_check FROM `messages` WHERE `status` ='new'");
$res= mysql_query($sql) or die(mysql_error());
$message_check= mysql_result($res, 0, 'message_check');

if ( $message_check == 0 ) {
    $text ='You have no new messages';
}elseif ( $message_check == 1) {
      $text ='You have <b>1</b> new message';
}else{
      $text ='You have <b>$message_check</b> new messages';    
}     
?>[/code]



The only problem is, in the html, it just displays the $text like this: You have [b]$message_check[/b] messages. I am using this in the html [code=php:0]<p><?php echo $text; ?></p>[/code] to display $text.

Any suggestions on how to accomplish this would be great.
Link to comment
https://forums.phpfreaks.com/topic/14383-select-count/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.