user663049
user663049

Reputation: 1178

How do i write this amount of code into a PHP if statement?

How do i write an PHP if statement that says if this code

$sql=mysql_query("select * from updates ORDER BY update_time DESC LIMIT 9");
while($row=mysql_fetch_array($sql))
{
$msg_id=$row['update_time'];
$message=$row['item_content'];
?>

<?php echo $message; ?>

<?php } ?> 

has the same output as a variable, then do nothing. I'm only asking because i dont know how to put this amount of code into an if statement. If anyone knows please post, thanks :)

Upvotes: 0

Views: 58

Answers (1)

Majid Fouladpour
Majid Fouladpour

Reputation: 30252

Instead of echoing $message in each iteration build a $messages string to use in your if:

while($row=mysql_fetch_array($sql))
{
$msg_id=$row['update_time'];
$messages .= $row['item_content'];
}
if($messages != $old_messages) {
  // do something
}

Upvotes: 1

Related Questions