I've read a lot of information about the determination of a even/odd number and using it to change the class of a div.
In my case I want to switch the position of divs called MessagePicture and MessageText every new message posted.
- Picture left, Text right
- Picture right, Text left
- Picture left, Text right
- ect.
This is the code I am using to display the messages, I also included one of my tries to get the even/odd code to work.
Can anyone tell me what I should change to get it to work?
<?PHP
$Query =
"
SELECT
ID,
NameBox,
MessageBox,
Code
FROM
messages
ORDER BY
ID
DESC LIMIT 10
";
$Result = mysql_query($Query);
if(!$Result)
{
echo 'ERROR: '.mysql_error();
}
else
{
if(mysql_num_rows($Result) == 0)
{
echo 'No results';
}
else
{
$i = 0;
$class = (++$i % 2) ? 'even' : 'odd';
while
($Row = mysql_fetch_assoc($Result))
echo '
<div id="MessageWrapper">
<div id="MessagePicture" class="'.$class.'">
<style>
#MessagePicture {
background-image: url(../../../Images/'.stripslashes($Row['Code']).'.png);
background-repeat: no-repeat;
background-position: center
</style>
</div>
<div id="MessageText" class="'.$class.'">
<div id="MessageTitle">
<h1>'.$Row['NameBox'].'</h1>
</div>
<div id="MessageContent">
<p>'.nl2br($Row['MessageBox']).'</p>
</div>
</div>
</div>
';}}}?>