stelthius Posted March 3, 2009 Share Posted March 3, 2009 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 More sharing options...
trq Posted March 3, 2009 Share Posted March 3, 2009 Take look at mysql_num_rows. Link to comment https://forums.phpfreaks.com/topic/147747-solved-table-count-with-php/#findComment-775563 Share on other sites More sharing options...
stelthius Posted March 3, 2009 Author Share Posted March 3, 2009 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 https://forums.phpfreaks.com/topic/147747-solved-table-count-with-php/#findComment-775629 Share on other sites More sharing options...
redarrow Posted March 3, 2009 Share Posted March 3, 2009 first. Count the messages via the users id, then valadate via mysql_num_rows() Link to comment https://forums.phpfreaks.com/topic/147747-solved-table-count-with-php/#findComment-775635 Share on other sites More sharing options...
redarrow Posted March 3, 2009 Share Posted March 3, 2009 dont need the users id or any think else, you need to cheek all messages mate. <?php database connection. $sql = "SELECT * FROM messages"; $res=mysql_query($sql)or die(mysql_error()); if(mysql_num_rows($res)>=50){ //echo } ?> Link to comment https://forums.phpfreaks.com/topic/147747-solved-table-count-with-php/#findComment-775642 Share on other sites More sharing options...
stelthius Posted March 3, 2009 Author Share Posted March 3, 2009 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 https://forums.phpfreaks.com/topic/147747-solved-table-count-with-php/#findComment-775647 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.