Jump to content

why is this not working ????


shorty3

Recommended Posts

right this is from my database

Database: inbox

 

right i did this code:

<?php $totalmess2 = mysql_num_rows(mysql_query("SELECT read='0' FROM inbox")); ?>

 

then

<?php echo "$totalmess2"; ?>

 

ive got read in my inbox which just shows whether some one as read the message or not 1=read 0=unread

 

 

i want to know the total unread message there is in my inbox database whats going wrong

Link to comment
Share on other sites

So many things wrong with this code.

 

Firstly, executing mysql_query() within mysql_num_rows() like that is ridiculous. it gives you absolutely no opportunity to check your query for success before attempting to use its result.

 

Speaking of which, your query is failing because its syntax is incorrect. You might try.....

 

SELECT id FROM inbox WHERE read = '0'

 

So, that would be....

 

if ($result = mysql_query("SELECT id FROM inbox WHERE read = '0'")) {
  echo mysql_num_rows($result);
}

 

Now, considering you only want a count and not the actual data, this would be even better.

 


if ($result = mysql_query("SELECT COUNT(id) AS cnt FROM inbox WHERE read = '0'")) {
  if (mysql_num_rows($result)) {
    $row = mysql_fetch_assoc($result);
    echo $row['cnt'];
  }
}

Link to comment
Share on other sites

nope it didn`t work ?

 

Thats helpful. Try debugging it.

 

if ($result = mysql_query("SELECT COUNT(id) AS cnt FROM inbox WHERE read = '0'")) {
  if (mysql_num_rows($result)) {
    $row = mysql_fetch_assoc($result);
    echo $row['cnt'];
  } else {
    // no records found.
  }
} else {
  trigger_error(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.