我想写这样的东西:
<?php
$comment = mysql_query("SELECT * FROM `communication` WHERE `ID`='$index' order by `Date_add` desc");
echo "<div class=\"row\">";
while ($com = mysql_fetch_assoc($comment)) {
$side = mysql_query("SELECT Type FROM `client` WHERE `ID`='$comtype'");
if ($side[0]==2) {
echo "<div class=\"left\">"; // and i want to execute this line only when the next value of $side is equal to 1 or 9
echo "<div class=\"inside1\">"
...
echo "</div>";
echo "</div>"; // same as above, close div only, when the next value of $side is equal to 1 or 9
} else if ($side[0]==1 || $side[0]==9) {
echo "<div class=\"right\">"; // Same here i want to execute this line only when the next value of $side is equal to 2
echo "<div class=\"inside2\">";
...
echo "</div>";
echo "</div>"; // same as above, close div only, when the next value of $side is equal to 2
}
}
echo "</div>";
我需要执行整个代码,但我在 div 中有 div,并且我想要并在 $side[0] 的值不同时执行。例如:
Loop step 1:
$side[0]=2
so i want to execute: <div class=left> and everything in this div.
Loop step 2:
$side[0]=2 again
so i want to execute all in <div class=left> but i dont want to create another <div class=left>
Lopp step 3:
$side[0]=1
so previously $side[0] was equal 2, so now i want to create <div class=left> and everything in this div
Lopp step 4:
$side[0]=1 again
so i want to execute all in <div class=right> but i dont want to create another <div class=right>
etc...
有谁知道如何达到这样的效果?感谢您的建议帮助。