Reputation: 325
<?php
if ($username)
echo $username
else
echo '<form class="navbar-form navbar-right" action="login.php">
<button class="btn btn-custom">Log ind</button>
</form>';
?>
I have this code and I want to be able to push my $username variable to the rightside, where my Login button was, when an user logs into my side. How would this be done?
I can't use
echo <p class="btn btn-custom"> <? $username; ?> </p>
what would be a possible way to do it?
Upvotes: 0
Views: 115
Reputation: 171
Here you need to use div with float right style, float right style push the content on right side.
<?php
if ($username)
echo '<div style="float:right">' . $username . '</div>';
else
echo '<form class="navbar-form navbar-right" action="login.php">
<button class="btn btn-custom">Log ind</button>
</form>';
?>
Upvotes: 1
Reputation: 23978
<?php
if ($username) {
echo '<div style="float:right">'.$username . '</div>';
}
else {
echo '<form class="navbar-form navbar-right" action="login.php">
<button class="btn btn-custom">Log ind</button>
</form>';
}
?>
Use CSS' float:right
attribute to push the $username
to right.
Upvotes: 0
Reputation: 1771
Easiest way to do so is like this: you can echo a variable following a string with
echo 'string whatever'.$variablename.'more string';
<?php
if ($username)
echo '<div class="username">'.$username .'</div>';
else
echo '<form class="navbar-form navbar-right" action="login.php">
<button class="btn btn-custom">Log ind</button>
</form>';
?>
and then simply give the class .username
the same positioning as navbar-right
Upvotes: 2
Reputation: 602
Possibly you looking for this:
You are in right direction but need to use the echo
statement to print $username
<?php
if ($username)
echo '<p class="btn btn-custom">' . $username . '</p>';
else
echo '<form class="navbar-form navbar-right" action="login.php">
<button class="btn btn-custom"><?php echo $username; ?></button>
</form>';
?>
Upvotes: 1
Reputation: 2874
Wrap the $username
in a div/span element and align it like you want with css (maybe you can reuse the css class you used for your login link).
Example:
<?php
if ($username) {
echo '<div class="navbar-form navbar-right">' . $username . '</div>';
} else {
echo '<form class="navbar-form navbar-right" action="login.php">
<button class="btn btn-custom">Log ind</button>
</form>';
}
?>
Upvotes: 2
Reputation: 647
<?php echo $username; ?>
Best way to implement this will be making use of smarty template.
Upvotes: 0