Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
how to add code in echo?
Old 06-20-2010, 01:28 PM how to add code in echo?
asmalik12's Avatar
Extreme Talker

Posts: 173
Name: Abdullah Saleem
Trades: 0
Hi,

How could I add the following code :

PHP Code:
<br />

<a class="topbarlink" href="<?php echo get_settings('home'); ?>/wp-login.php"><?php $toplinks6 get_option('stylewp_toplinks6'); echo $toplinks6?></a> &nbsp;|&nbsp; <a class="topbarlink" href="<?php echo get_settings('home'); ?>/wp-login.php?action=register"><?php $toplinks4 get_option('stylewp_toplinks4'); echo $toplinks4?></a>
after
PHP Code:
} else {
    echo 
'Welcome, Guest!'
Actual Script is here, what I want

PHP Code:
<?php
if ( is_user_logged_in() ) {
    global 
$current_user;
      
get_currentuserinfo();

    echo 
'Welcome, <b>' $current_user->display_name "</b>\n";

} else {
    echo 
'Welcome, Guest!';
};

?>
If user logged in then display Logout else, Login & Register, which is above in the code.
__________________
"Think 100 times before you take a decision, But once that decision is taken, stand by it as one man." - Quaid-e-Azam

Last edited by asmalik12; 06-20-2010 at 01:30 PM..
asmalik12 is offline
Reply With Quote
View Public Profile Visit asmalik12's homepage!
 
 
Register now for full access!
Old 06-20-2010, 02:23 PM Re: how to add code in echo?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Is this what you mean:
PHP Code:
<?php
if ( is_user_logged_in() ) {
    global 
$current_user;
      
get_currentuserinfo();

    echo 
'Welcome, <b>' $current_user->display_name "</b>\n";

} else {
    echo 
'Welcome, Guest!';
?>
<br />

<a class="topbarlink" href="<?php echo get_settings('home'); ?>/wp-login.php"><?php $toplinks6 get_option('stylewp_toplinks6'); echo $toplinks6?></a> &nbsp;|&nbsp; <a class="topbarlink" href="<?php echo get_settings('home'); ?>/wp-login.php?action=register"><?php $toplinks4 get_option('stylewp_toplinks4'); echo $toplinks4?></a>
<?php
}

?>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-21-2010, 03:20 AM Re: how to add code in echo?
Phunk Rabbit's Avatar
Ultra Talker

Posts: 255
Name: John Nerush
Location: Milton Keynes, UK
Trades: 0
Rather than opening and closing PHP tags all over the place:

PHP Code:
 <?php 
if ( is_user_logged_in() ) { 
      global 
$current_user
      
get_currentuserinfo(); 

      echo 
'Welcome, <b>' $current_user->display_name "</b>\n"

} else { 
      echo 
'Welcome, Guest!'

      
$toplinks6 =  get_option('stylewp_toplinks6'); 
      
$toplinks4 get_option('stylewp_toplinks4'); 

      echo 
'<br /><a class="topbarlink" href="' get_settings('home') . '/wp-login.php">' $toplinks6 '</a>  &nbsp;|&nbsp; <a class="topbarlink" href="' get_settings('home') . '/wp-login.php?action=register">' $toplinks4 '</a>  ';



?>
__________________

Please login or register to view this content. Registration is FREE

Learn professional skills from professional people, from $6.50 a month.

Last edited by Phunk Rabbit; 06-21-2010 at 03:22 AM..
Phunk Rabbit is offline
Reply With Quote
View Public Profile Visit Phunk Rabbit's homepage!
 
Old 06-21-2010, 03:23 AM Re: how to add code in echo?
Phunk Rabbit's Avatar
Ultra Talker

Posts: 255
Name: John Nerush
Location: Milton Keynes, UK
Trades: 0
Just looking over the code and suddenly realised, how come you are mixing OOP and procedural code?
__________________

Please login or register to view this content. Registration is FREE

Learn professional skills from professional people, from $6.50 a month.
Phunk Rabbit is offline
Reply With Quote
View Public Profile Visit Phunk Rabbit's homepage!
 
Old 06-21-2010, 09:04 PM Re: how to add code in echo?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by Phunk Rabbit View Post
Just looking over the code and suddenly realised, how come you are mixing OOP and procedural code?
What exactly is wrong with the code? It is common in PHP to use objects in code that would otherwise be purely procedural. The object he uses, $current_user, is a global in wordpress. It doesn't seem to me like he is using it inappropriately.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-22-2010, 03:51 AM Re: how to add code in echo?
Phunk Rabbit's Avatar
Ultra Talker

Posts: 255
Name: John Nerush
Location: Milton Keynes, UK
Trades: 0
I was under the (obvously wrong lol) impression that when using OOP code you should make an effort to have the whole site running in OOP rather than mixing objects and procedual code.

Bereing in mind i never attually said there was anything wrong with the code but instead was looking to see if there was a particular reason he was using both methods
__________________

Please login or register to view this content. Registration is FREE

Learn professional skills from professional people, from $6.50 a month.
Phunk Rabbit is offline
Reply With Quote
View Public Profile Visit Phunk Rabbit's homepage!
 
Old 06-22-2010, 01:45 PM Re: how to add code in echo?
Super Talker

Posts: 144
Name: Nick Mallare
Location: Olathe, KS
Trades: 0
Quote:
Originally Posted by Phunk Rabbit View Post
I was under the (obvously wrong lol) impression that when using OOP code you should make an effort to have the whole site running in OOP rather than mixing objects and procedual code.

Bereing in mind i never attually said there was anything wrong with the code but instead was looking to see if there was a particular reason he was using both methods
A general rule of thumb to remember is that OOP code can have a lot of overhead. It should be used only when needed and only if applicable. Do not get me wrong, I love a good site that utilizes the power of PHP OOP; however, it does have its time, place and purpose.

Nick
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
nmallare is offline
Reply With Quote
View Public Profile Visit nmallare's homepage!
 
Old 06-23-2010, 02:55 AM Re: how to add code in echo?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by nmallare View Post
A general rule of thumb to remember is that OOP code can have a lot of overhead. It should be used only when needed and only if applicable.

Where are you getting that from? Unless I'm mistaken the overhead (if any) of using objects is negligible. I can't think of any circumstance (in PHP) where I would advise against using objects due to performance.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-23-2010, 05:39 AM Re: how to add code in echo?
asmalik12's Avatar
Extreme Talker

Posts: 173
Name: Abdullah Saleem
Trades: 0
I have done it. Someone culd now tell me how to add javascript in echo?

Javascript Code :

Code:
<a href="#" onclick="javascript: if(sIB.style.display=='none'){sIB.style.display='block';}else {sIB.style.display='none';}">Sign In</a>
<p>More Content</p>

<div id="sIB" style="display:none;margin-top:-50px;position:absolute;background:#888888;padding:20px;border:10px solid #666666;color:#ffffff;">Sign In Box Contents Here</div>
<p>Content Content Content</p><p>Hoooray for content</p>
I want to display this box in Sign in link :

PHP Code:
   $toplinks6 =  get_option('stylewp_toplinks6');  
      
$toplinks4 get_option('stylewp_toplinks4');  

      echo 
'<br /><a class="topbarlink" href="' get_settings('home') . '/wp-login.php">' $toplinks6 '</a>  &nbsp;|&nbsp; <a class="topbarlink" href="' get_settings('home') . '/wp-login.php?action=register">' $toplinks4 '</a>  '
__________________
"Think 100 times before you take a decision, But once that decision is taken, stand by it as one man." - Quaid-e-Azam
asmalik12 is offline
Reply With Quote
View Public Profile Visit asmalik12's homepage!
 
Old 06-23-2010, 07:03 AM Re: how to add code in echo?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
HTML and javascript are client side code. There is no special way to "add javascript in echo"; all output is the same to PHP. If you want something to be included in the output received by the user then either echo it as a string, or close the PHP tags and include the code just as you would normal html or javascript code.
PHP Code:
<?php
//php code here
?>
<a href="#" onclick="javascript: if(sIB.style.display=='none'){sIB.style.display='block';}else {sIB.style.display='none';}">Sign In</a>
<p>More Content</p>

<div id="sIB" style="display:none;margin-top:-50px;position:absolute;background:#888888;padding:20px;border:10px solid #666666;color:#ffffff;">Sign In Box Contents Here</div>
<p>Content Content Content</p><p>Hoooray for content</p>
<?php
//more php here
?>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-23-2010, 09:46 AM Re: how to add code in echo?
Super Talker

Posts: 144
Name: Nick Mallare
Location: Olathe, KS
Trades: 0
Quote:
Originally Posted by NullPointer View Post
Where are you getting that from? Unless I'm mistaken the overhead (if any) of using objects is negligible. I can't think of any circumstance (in PHP) where I would advise against using objects due to performance.
It is just common sense. If you have a class that has thirty variables and fifteen functions, but you only need to use four of the variables and two of the functions, then you are going to have included a lot of unnecessary code. This is what I was getting at.

That said, as I stated before, I prefer OOP code as it is cleaner. But for optimizing code, procedural can be a very viable solution.

Nick
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
nmallare is offline
Reply With Quote
View Public Profile Visit nmallare's homepage!
 
Old 06-23-2010, 08:22 PM Re: how to add code in echo?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by nmallare View Post
It is just common sense. If you have a class that has thirty variables and fifteen functions, but you only need to use four of the variables and two of the functions, then you are going to have included a lot of unnecessary code. This is what I was getting at.

That said, as I stated before, I prefer OOP code as it is cleaner. But for optimizing code, procedural can be a very viable solution.
I think you're optimizing in the wrong places. Even in the circumstance you described the performance difference would be negligible. Even if you had so many instances of such a class that it made a difference, the solution is to rethink your approach, not ditch OOP.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-23-2010, 10:49 PM Re: how to add code in echo?
Super Talker

Posts: 144
Name: Nick Mallare
Location: Olathe, KS
Trades: 0
Quote:
Originally Posted by NullPointer View Post
I think you're optimizing in the wrong places. Even in the circumstance you described the performance difference would be negligible. Even if you had so many instances of such a class that it made a difference, the solution is to rethink your approach, not ditch OOP.
Well, we will have to agree to disagree. I am a huge proponent of optimizing at every step, not just some.

Nick
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
nmallare is offline
Reply With Quote
View Public Profile Visit nmallare's homepage!
 
Old 08-03-2010, 02:35 AM Re: how to add code in echo?
Novice Talker

Posts: 13
Trades: 0
OOP code can be of your used. It is an object-oriented programming code. I prefer this. Let me clarify, I have no grudges against PHP.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
darylnelson is offline
Reply With Quote
View Public Profile
 
Old 08-04-2010, 01:04 PM Re: how to add code in echo?
Novice Talker

Posts: 10
Name: Muhammad Umer Farooq
Trades: 0
PHP Code:
<?php
if ( isset(is_user_logged_in() )) {
    global 
$current_user;
      
get_currentuserinfo();

    echo 
'Welcome, <b>' $current_user->display_name "</b>\n";

} else {
    echo 
'Welcome, Guest!';
};

?>
omerfarooq123 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to how to add code in echo?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.43330 seconds with 12 queries