
01-12-2011, 09:56 PM
|
|
Newbie
|
|
Join Date: Dec 2010
Posts: 16
|
|
Simple PHP question: echo leaving out <span>
The following code will output the value of the function but leaves out the span tags completely. I'm going crazy trying to figure out why. Help!
PHP Code:
<?php if(bp_friend_total_requests_count() > 0) echo "<span>".bp_friend_total_requests_count()."</span>" ?>
|

01-12-2011, 10:05 PM
|
|
Web Hosting Master
|
|
Join Date: Mar 2009
Posts: 596
|
|
Relying on the parser to add semicolons is BAD.
Why are you calling the function more than once? Store it in a variable, and do conditional and output on the variable.
Code:
<?php
$bp_friend_total_requests_count = bp_friend_total_requests_count();
if(is_int($bp_friend_total_requests_count) && $bp_friend_total_requests_count > 0) echo "<span>$bp_friend_total_requests_count</span>";
?>
__________________
[GB ≠ GiB] [MB ≠ MiB] [kB ≠ kiB] [1000 ≠ 1024] [Giga ≠ gram] [Mega ≠ milli] [Kelvin ≠ kilo] [Byte ≠ bit]
There is no millibit. There is no gram-bit. There is no Kelvin-Byte.
|

01-12-2011, 10:09 PM
|
|
Newbie
|
|
Join Date: Dec 2010
Posts: 16
|
|
I tried that and got the same output. That shouldn't matter anyways even if it is poor sytnax
|

01-12-2011, 10:15 PM
|
|
Newbie
|
|
Join Date: Dec 2010
Posts: 16
|
|
The messages version of that works perfectly but the $requests does not output the spans or the parentheses around the variable. I don't get it...
PHP Code:
<li class="topnav">
<a title="Messages" href="<?php echo bp_loggedin_user_domain() ?>messages/" id="admin-messages">Messages <?php $messages = messages_get_unread_count(); if($messages > 0) echo "<span>".$messages."</span>"; ?></a>
<ul>
<li class="alt">
<a href="<?php echo bp_loggedin_user_domain() ?>messages/inbox/" id="bp-admin-inbox">Inbox <?php if($messages > 0) echo "(".$messages.")"; ?></a>
</li>
<li>
<a href="<?php echo bp_loggedin_user_domain() ?>messages/sentbox/" id="bp-admin-sentbox">Sent Messages</a>
</li>
<li class="alt">
<a href="<?php echo bp_loggedin_user_domain() ?>messages/compose/" id="bp-admin-compose">Compose</a>
</li>
<li class="last">
<a href="<?php echo bp_loggedin_user_domain() ?>messages/notices/" id="bp-admin-notices">Notices</a>
</li>
</ul>
</li>
<li class="topnav">
<a title="Friends" href="<?php echo bp_loggedin_user_domain() ?>friends/" id="admin-friends">Friends <?php $requests = bp_friend_total_requests_count(); if($requests > 0) echo "<span>".$requests."</span>"; ?></a>
<ul>
<li class="alt">
<a href="<?php echo bp_loggedin_user_domain() ?>friends/my-friends/" id="bp-admin-friends-my-friends">My Friends</a>
</li>
<li class="last">
<a href="<?php echo bp_loggedin_user_domain() ?>friends/requests/" id="bp-admin-requests">Requests <?php if($requests > 0) echo "(".$requests.")"; ?></a>
</li>
</ul>
</li>
|

01-12-2011, 10:22 PM
|
|
Web Hosting Guru
|
|
Join Date: May 2009
Location: Tennessee
Posts: 295
|
|
Quote:
Originally Posted by jetlej
The messages version of that works perfectly but the $requests does not output the spans or the parentheses around the variable. I don't get it...
|
I'm going to guess that $requests isn't greater than zero.
|

01-12-2011, 10:25 PM
|
|
Web Hosting Master
|
|
Join Date: Mar 2009
Posts: 596
|
|
var_dump($requests);
What is the actual value?
__________________
[GB ≠ GiB] [MB ≠ MiB] [kB ≠ kiB] [1000 ≠ 1024] [Giga ≠ gram] [Mega ≠ milli] [Kelvin ≠ kilo] [Byte ≠ bit]
There is no millibit. There is no gram-bit. There is no Kelvin-Byte.
|

01-12-2011, 10:48 PM
|
|
Newbie
|
|
Join Date: Dec 2010
Posts: 16
|
|
$requests outputs NULL, but echo bp_friend_total_requests_count() outputs 2
|

01-12-2011, 11:11 PM
|
|
Web Hosting Master
|
|
Join Date: Mar 2009
Posts: 596
|
|
Is your function doing output instead of returning a value?
__________________
[GB ≠ GiB] [MB ≠ MiB] [kB ≠ kiB] [1000 ≠ 1024] [Giga ≠ gram] [Mega ≠ milli] [Kelvin ≠ kilo] [Byte ≠ bit]
There is no millibit. There is no gram-bit. There is no Kelvin-Byte.
|

01-12-2011, 11:15 PM
|
|
Newbie
|
|
Join Date: Dec 2010
Posts: 16
|
|
Not sure, it's a core function in Buddypress, a community forum software. How can I check and if so is there a way around it?
Thanks again guys
|

01-12-2011, 11:57 PM
|
|
WHT Addict
|
|
Join Date: Dec 2010
Posts: 101
|
|
Have you tried replacing the " with '
This is PHP. ANYTHING goes!
__________________
█ BackupTeddy - Easy Linux Backups
█ Easiest automated backups for webmasters with VPS's or Servers
|

01-13-2011, 12:13 AM
|
|
Web Hosting Guru
|
|
Join Date: Jan 2011
Location: Vancouver, Canada
Posts: 329
|
|
Quote:
Originally Posted by jetlej
$requests outputs NULL, but echo bp_friend_total_requests_count() outputs 2
|
Take out the if statement and just put this:
PHP Code:
<?php echo "<span>" . bp_friend_total_requests_count() . "</span>"; ?>
What do you get?
What I'm suspecting is that the bp_friend_total_requests_count() function has an echo statement in it rather than a return value. If so, the null value you are getting would invalidate your if statement, but would still echo the integer since the function call does it.
Can you post the actual function code?
|

01-13-2011, 12:25 AM
|
|
Newbie
|
|
Join Date: Dec 2010
Posts: 16
|
|
Yes that was it! The function just echo-ed another function so I replaced the function and everything works.
Thanks so much Christian, and everyone else. Have an awesome night guys
|

01-13-2011, 12:28 AM
|
|
Web Hosting Guru
|
|
Join Date: Jan 2011
Location: Vancouver, Canada
Posts: 329
|
|
np  Glad it worked 
|

01-27-2011, 01:25 PM
|
|
Newbie
|
|
Join Date: Jan 2011
Posts: 19
|
|
Agree with Christian Little, there couldn't be any better way to solve you problem.
|

01-28-2011, 03:34 PM
|
|
Newbie
|
|
Join Date: Jan 2011
Location: Arizona
Posts: 11
|
|
Quote:
Originally Posted by Backupteddy
Have you tried replacing the " with '
This is PHP. ANYTHING goes!
|
I know this is slightly off topic but something I just found out recently with a CLI script i was working on, we had to use " in order to get the \n to display correctly.
Pretty odd and still havent figured that one out...
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
| Postbit Selector |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
| Login: |
|
|
| Advertisement: |
|
|
| Web Hosting News: |
|
|
|