hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Simple PHP question: echo leaving out <span>
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

Simple PHP question: echo leaving out <span>

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 01-12-2011, 09:56 PM
jetlej jetlej is offline
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>" ?>

Reply With Quote


Sponsored Links
  #2  
Old 01-12-2011, 10:05 PM
petteyg359 petteyg359 is offline
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.

Reply With Quote
  #3  
Old 01-12-2011, 10:09 PM
jetlej jetlej is offline
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

Reply With Quote
Sponsored Links
  #4  
Old 01-12-2011, 10:15 PM
jetlej jetlej is offline
Newbie
 
Join Date: Dec 2010
Posts: 16
Here's the full code

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>

Reply With Quote
  #5  
Old 01-12-2011, 10:22 PM
Hostify Networks Hostify Networks is online now
Web Hosting Guru
 
Join Date: May 2009
Location: Tennessee
Posts: 295
Quote:
Originally Posted by jetlej View Post
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.

__________________
AudioProbe.net - Playing the best music from the 70s, 80s, 90s, 00s, and more...
Commercial free, high quality 192kb/s, and firewall friendly port 80!
Look for us in the iTunes Radio directory under Adult Contemporary

Reply With Quote
  #6  
Old 01-12-2011, 10:25 PM
petteyg359 petteyg359 is offline
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.

Reply With Quote
  #7  
Old 01-12-2011, 10:48 PM
jetlej jetlej is offline
Newbie
 
Join Date: Dec 2010
Posts: 16
$requests outputs NULL, but echo bp_friend_total_requests_count() outputs 2

Reply With Quote
  #8  
Old 01-12-2011, 11:11 PM
petteyg359 petteyg359 is offline
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.

Reply With Quote
  #9  
Old 01-12-2011, 11:15 PM
jetlej jetlej is offline
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

Reply With Quote
  #10  
Old 01-12-2011, 11:57 PM
Backupteddy Backupteddy is offline
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


Reply With Quote
  #11  
Old 01-13-2011, 12:13 AM
Christian Little Christian Little is offline
Web Hosting Guru
 
Join Date: Jan 2011
Location: Vancouver, Canada
Posts: 329
Quote:
Originally Posted by jetlej View Post
$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?

Reply With Quote
  #12  
Old 01-13-2011, 12:25 AM
jetlej jetlej is offline
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

Reply With Quote
  #13  
Old 01-13-2011, 12:28 AM
Christian Little Christian Little is offline
Web Hosting Guru
 
Join Date: Jan 2011
Location: Vancouver, Canada
Posts: 329
np Glad it worked

Reply With Quote
  #14  
Old 01-27-2011, 01:25 PM
abhinavs abhinavs is offline
Newbie
 
Join Date: Jan 2011
Posts: 19
Agree with Christian Little, there couldn't be any better way to solve you problem.

Reply With Quote
  #15  
Old 01-28-2011, 03:34 PM
synrg synrg is offline
Newbie
 
Join Date: Jan 2011
Location: Arizona
Posts: 11
Quote:
Originally Posted by Backupteddy View Post
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...

Reply With Quote
Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying field value into a <span></span> latheesan Programming Discussion 1 06-25-2007 02:59 PM
question about Echo Inc leenamendez Ecommerce Hosting & Discussion 5 08-08-2006 09:40 AM
simple php question aus-e Programming Discussion 4 04-12-2003 06:49 PM
question about echo/print Gem Hexen Programming Discussion 7 08-29-2002 04:38 AM
Simple PHP question (php.ini loaded?) Domenico Hosting Security and Technology 1 10-22-2001 09:05 AM

Related posts from TheWhir.com
Title Type Date Posted
The Value of Your Intellectual Property Blog 2013-05-06 17:43:13
WHIR Toronto Event Rocked Four Years in a Row Blog 2012-05-22 11:29:19
What the new version of Google Analytics brings to your business Blog 2011-12-20 15:56:29
Huge fun in Houston at Hughes Hangar Blog 2011-11-11 16:17:03
WHIR TV Tours Cbeyond's Louisville, KY Data Center Whir Tv 2011-10-11 00:00:00


Tags
echo, php, span

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?