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
https://forums.phpfreaks.com/topic/147747-solved-table-count-with-php/
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.

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

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.