Saturday, 7 September 2013

PHP if statement inside if statement

PHP if statement inside if statement

i've been trying to put a IF statment inside of another IF, and show it
int the td cell, but it's been quit difficult to me, i would apreciate if
someone could help me.
The if ($size) works when its outside the if($i). but when i try to put it
inside.. it gives me an error. I strongly believe it's a concatenate
problem that i'm not aware. the error is Parse error: syntax error,
unexpected 'if' (T_IF) in ..\htdocs\room\index.php on line 50
So what i want is basicaly to put the $size showing on the td, like all
other variables, and with the if condition.
<?php
$messages = "";
$sqli = mysqli_query($dbc,"SELECT * FROM fox ORDER BY data DESC LIMIT 20");
$i = 0;
$productCount = mysqli_num_rows($sqli);
if ($productCount > 0) {
while($row = mysqli_fetch_array($sqli)){
$id = $row["id"];
$msg_1 = $row['msg_1'];
$msg_email = $row['msg_email'];
$assunto = $row['assunto'];
$mensagem = $row['mensagem'];
$data = $row['data'];
$size = $row['size'];
if (!$size){ echo ' X';} else {echo "<img src='../style/check.jpg'
width='20' height='20' />";}
if ($i % 2 == 0) { $messages .= '
<tr bgcolor="#f0eded">
<td align="center">' . $msg_1 .'</td>
<td align="center">' . $msg_email .'</td>
<td align="center">' . $assunto .'</td>
<td align="center">' . $mensagem . '</td>
<td align="center">' . $data .'</td>
<td align="center">' . $size .'</td>
<td align="center"><a href="index.php?id=' . $id .
'">Respond</a>&nbsp;<b>/</b>&nbsp;<a
href="#">Eliminate</a></td>
</tr>';
} else {
$messages .= '
<tr background-color= "#ffffff">
<td align="center">' . $msg_1 .'</td>
<td align="center">' . $msg_email .'</td>
<td align="center">' . $assunto .'</td>
<td align="center">' . $mensagem . '</td>
<td align="center">' . $data .'</td>
<td align="center">' . $size .'</td>
<td align="center"><a href="index.php?id=' . $id . '">
Respond</a>&nbsp;<b>/</b>&nbsp;<a href="#">Eliminate </a></td>
</tr>';
}
$i++;
}
}else{
$messages = "<b>No msg in DB.</b>";
}
?>
Sorry about the screenshot! and Thank you.

No comments:

Post a Comment