Jump to content

[SOLVED] table count with php


stelthius

Recommended Posts

Hi guys,

 

Im trying to stop a user A sending a pm to user B if user B has more than 50 pm's in there inbox but i cant quite work out were im going wrong it just completely ignores the check and sends the pm anyway,

 

Can  anyone help me on this please,

 

//Get their private message count
$sql = mysql_query ("SELECT id FROM messages WHERE receiver='$receiver'");
$row = mysql_fetch_array ($sql);
$num_rows = $row['id'];

//You cant have more than 50 private messages, if they try sending a message to a user with a full inbox return an error message
if ($num_rows >= 50)
{
$error = 'The inbox of the user you are trying to send a message to is full so we were unable to deliver your message.';
}
else
{ 
mysql_query("INSERT INTO messages (reciever, sender, subject, message) VALUES('$reciever', '$user', '$subject', '$message')") or die (mysql_error());
}

 

 

Thanks Rick

Link to comment
Share on other sites

Ok after re-trying my code here i have tried the following and none have come to work for me its still skipping this, i also used what you said thorpe i was using that when trying to do this.

 

* This failed to work

//Get their private message count
$sql = mysql_query ("SELECT id FROM messages WHERE username='$reciever'");
$row = mysql_fetch_array ($sql);
$num_rows = $row['id'];

//You cant have more than 50 private messages, if they try sending a message to a user with a full inbox return an error message
if ($num_rows >= 50)
{
$error = 'The inbox of the user you are trying to send a message to is full so we were unable to deliver your message.';
}
else
{ 

 

 

 

* This failed to work

//Get their private message count
$sql = mysql_query ("SELECT * FROM messages WHERE username='$reciever'");
$row = mysql_fetch_array ($sql);
$num_rows = mysql_num_rows($row);

//You cant have more than 50 private messages, if they try sending a message to a user with a full inbox return an error message
if ($num_rows >= 50)
{
$error = 'The user you are trying to send a message to has 50 private messages, sorry but we cant send your message untill that user deletes some of their messages.';
}
else
{ 

 

 

* This failed to work

//Get their private message count
$sql = mysql_query ("SELECT * FROM messages WHERE username='$reciever'");
$row = mysql_fetch_array ($sql);
$num_rows = mysql_num_rows($sql);

//You cant have more than 50 private messages, if they try sending a message to a user with a full inbox return an error message
if ($num_rows >= 50)
{
$error = 'The user you are trying to send a message to has 50 private messages, sorry but we cant send your message untill that user deletes some of their messages.';
}
else
{ 

 

 

Im out of ideas now and its confusing the life out of me, any help would be great.

Link to comment
Share on other sites

Sorry guys,

 

I got it to work doing this,

 

//Get their private message count
$sql = mysql_query ("SELECT id FROM messages WHERE reciever='$reciever'");
$num_rows = mysql_num_rows($sql);

//You cant have more than 50 private messages, if they try sending a message to a user with a full inbox return an error message
if ($num_rows >= 50)
{
$error = 'The user you are trying to send a message to has 50 private messages so we cant send your message untill that user deletes some of their messages.';
}
else
{ 

 

But fixing that now re-arranges how my pm's show in the inbox so one fixed one created lol

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.