PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 28th, 2012, 09:29 PM
paulocore paulocore is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 16 paulocore User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 37 m 45 sec
Reputation Power: 0
PM System PHP

Hello there.

I've made one PM System PHP like 1 day ago, still working on it, its the first time i'm doing it, now i'm coding the inbox, did the count already, now i'm doing the echo's, but i'm not getting on how to fix this.

I've made something like this :

If theres 1 new message it will be Inbox(1 new message)
If theres 2 or more new messages it will be Inbox(2 new messages)
If theres no messages it will be Inbox(0 no messages)
I want it to be Inbox(No messages)

Ill paste here the code i'm using if someone could give me the right code for it, i will be thankfull.

Code:
<?php echo
 $msgs; 
if($msgs > 0) 
{ 
 if($msgs == 1)  
{   
echo ' new message'; 
 }  
else 
 {   
echo ' new messages';  
} 
} 
else 
{  
echo ' no messages'; 
} 
?>


Code:
<?php $user = $_SESSION['user']; 
$count = mysql_query("SELECT COUNT(message_read) AS unread FROM messages WHERE to_user = '".$user."' AND message_read = 0"); 
$msgs = mysql_result($count, 'unread'); ?>		


Thanks.

Reply With Quote
  #2  
Old December 28th, 2012, 09:43 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,833 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 1 h 5 m 18 sec
Reputation Power: 811
Hi,

the code is all crammed into one line, so it's hard to read.

But as far as I can tell, you have to move the echo $msgs; into the outermost "if" statement so that the count will only be shown in case of $msgs > 0.

Reply With Quote
  #3  
Old December 28th, 2012, 09:50 PM
paulocore paulocore is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 16 paulocore User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 37 m 45 sec
Reputation Power: 0
Quote:
Originally Posted by Jacques1
Hi,

the code is all crammed into one line, so it's hard to read.

But as far as I can tell, you have to move the echo $msgs; into the outermost "if" statement so that the count will only be shown in case of $msgs > 0.


Edited the post, check it please.

Reply With Quote
  #4  
Old December 28th, 2012, 09:51 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,833 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 1 h 5 m 18 sec
Reputation Power: 811
My suggestion still holds true.

Reply With Quote
  #5  
Old December 28th, 2012, 09:54 PM
paulocore paulocore is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 16 paulocore User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 37 m 45 sec
Reputation Power: 0
Quote:
Originally Posted by Jacques1
My suggestion still holds true.


edited the code, now it looks like this, but i still couldn't figure how do i make this without appearing the 0.

Code:
<?php
echo $msgs;
if($msgs == 0)
{
 echo 'no messages';
}
{
 if($msgs == 1)
 {
  echo ' new message';
 }
 elseif($msgs > 1)
 {
  echo ' new messages';
 }
}
?>

Reply With Quote
  #6  
Old December 28th, 2012, 10:46 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,833 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 1 h 5 m 18 sec
Reputation Power: 811
Please read my reply again. I did not say that you should change the "if" statement. I said this:

Quote:
Originally Posted by Jacques1
you have to move the echo $msgs; into the outermost "if" statement so that the count will only be shown in case of $msgs > 0.


So you have to do this:
PHP Code:
<?php

if($msgs 0)
{
    echo 
$msgs;            // only display $msgs if $msgs > 0
    
if($msgs == 1)
    {
        echo 
' new message';
    }
    else
    {
        echo 
' new messages';
    }
}
else
{
    echo 
' no messages';
}


The logic behind this should be pretty simple: Currently, your code displays the count in any case. That's not what you want. You only want to display the count if it's bigger than 0. So you have to move the "echo" inside the corresponding "if" statement. Now you have: if the count is bigger, then display it (otherwise don't).

I should also tell you that your code is open to SQL injections and XSS and that the "mysql_" functions are ancient, but I'm a bit tired of this ...

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PM System PHP

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap