Title: text alignment in php
Tags: php;jquery;html;mysql;css
Question: i will like to align my text so that when i send a message, it appears on the left, but its a reply, the text appears on the right ... i dont know whether to use "text-align:left", position or align. here is my code
if ($row['username'] == $username)
$color = 'blue';
$align:left; // dont know if this is right
$color = 'red';
$align:right; // dont know if this is right
echo '<i&gt;<p style="font-family:arial;color:'.$color.';font-size:15px;"&gt; <strong&gt;' . $row['username']. '</strong&gt;: ' . $mymessage.'</i&gt;</p&gt;';
Comment: or generate special class for element in php code and define this class in css.

Comment: @E_ERROR its kinda hilarious that your username is what PHP would generate with that statement

Comment: `$align:left;` is incorrect PHP statement

Comment: try using float: right or float:left


Here is another answer: Would be better if you use CSS classes for that.
For example, you could have a class message and a class reply:
<style&gt;
.message {
color: blue;
text-align: left;
.reply {
color: red;
text-align: right;
</style&gt;
And then in PHP:
if ($row['username'] == $username)
$class = "message";
$class = "reply";
echo "<p class='$class'&gt;
<strong&gt;{$row['username']}</strong&gt;: $mymessage
</p&gt;';
Your code will look way more clean.

Here is another answer: Try this,
$css =  ($row['username'] == $username) ? 'color:blue;text-align:left;' : 'color:red;text-align:right;';
echo '<i&gt;<p style="font-family:arial;font-size:15px;'.$css.'"&gt; <strong&gt;' . $row['username']. '</strong&gt;: ' . $mymessage.'</i&gt;</p&gt;';

Here is another answer: Set it exactly the same way you're setting color.
For instance:
$align='right';
echo '<i&gt;<p style="font-family:arial;color:'.$color.';text-align:'.$align.';font-size:15px;"&gt; <strong&gt;' . $row['username']. '</strong&gt;: ' . $mymessage.'</i&gt;</p&gt;';

Here is another answer: just use:
if ($row['username'] == $username)
echo '<i&gt;<p style="font-family:arial;color:blue;float:left;font-size:15px;"&gt; <strong&gt;' . $row['username']. '</strong&gt;: ' . $mymessage.'</i&gt;</p&gt;';
echo '<i&gt;<p style="font-family:arial;color:red;float:right;font-size:15px;"&gt; <strong&gt;' . $row['username']. '</strong&gt;: ' . $mymessage.'</i&gt;</p&gt;';

Here is another answer: This should work:
if ($row['username'] == $username)
$color = 'blue';
$align = 'left';
$color = 'red';
$align = 'right';
echo '<i&gt;<p style="text-align:' . $align . ';font-family:arial;color:'.$color.';font-size:15px;"&gt; <strong&gt;' . $row['username']. '</strong&gt;: ' . $mymessage.'</i&gt;</p&gt;';

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 5, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:03/12/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<php><jquery><html><mysql><css>', 'Title': 'text alignment in php', 'ViewCount': 4813, 'id': 15368883, 'user_AboutMe': None, 'user_AccountId': 2423931.0, 'user_DisplayName': 'user2116287', 'user_Reputation': 77.0, 'user_Views': 20.0, 'user_id': 2116287.0}}