我遇到了一个问题,我可以在哪里放置我的</tr>
,以便它在一段时间内不会重复出现?
<table border="0" cellspacing="0" cellpadding="0" >
<tr>
<?php
while ($pF = mysql_fetch_array($stringVisits))
{
$BuID= mysql_real_escape_string($pF['BuID']);
$getByInfo = mysql_query("SELECT * FROM users_profile WHERE uID = '$BuID'") or
die(mysql_error());
$getByProfile = mysql_fetch_array($getByInfo);
$getByInf = mysql_query("SELECT full_name, sex FROM users WHERE id = '$BuID'") or
die(mysql_error());
$getByProfil = mysql_fetch_array($getByInf);
?>
<td class="viewercell" style="color: #CCC; font-size: 10px;">
<?php
echo "<a href='profil.php?id=".$BuID."'>";
echo "<img style='margin-right: 5px; width: 44px; height: 48px; border: 2px solid #FFF; ' src='images/profilePhoto/thumbs/";
if (!empty($getByProfile["photo_thumb"]))
{
echo $getByProfile["photo_thumb"];
} else {
echo "noPhoto_thumb.jpg";
}
echo "'>";
?>
</a>
</td>
我想关闭那个<tr>
并开始一个新的,但我怎么能这样做?如果我只是将</tr>
置于上面的^下,它将复制</tr>
,因为它在while()
内部如果我在关闭}
之后这样做,我就无法使用我的下一个tr中已经while()
的$ pF了。
我想在上面的profilephoto下显示一个新的tr。
答案 0 :(得分:1)
您可以打开和关闭内部的tr,当您进入循环时向右打开并在退出循环之前向右关闭。请参阅下面的代码,应该做的诀窍
<table border="0" cellspacing="0" cellpadding="0" >
<tbody>
<?php
// Check result array
if ($pF) {
while ($pF = mysql_fetch_array($stringVisits)) {
?>
<tr>
<?php
$BuID = mysql_real_escape_string($pF['BuID']);
$getByInfo = mysql_query("SELECT * FROM users_profile WHERE uID = '$BuID'") or
die(mysql_error());
$getByProfile = mysql_fetch_array($getByInfo);
$getByInf = mysql_query("SELECT full_name, sex FROM users WHERE id = '$BuID'") or
die(mysql_error());
$getByProfil = mysql_fetch_array($getByInf);
?>
<td class="viewercell" style="color: #CCC; font-size: 10px;">
<?php
$photo = !empty($getByProfile["photo_thumb"]) ? $getByProfile["photo_thumb"] : "noPhoto_thumb.jpg";
//
echo "<a href='profil.php?id=$BuID'>";
echo "<img style='margin-right: 5px; width: 44px; height: 48px; border: 2px solid #FFF; ' src='images/profilePhoto/thumbs/$photo' />";
?>
</td>
</tr>
<?php
} // End of While
} else {
?>
<tr>
<td>
No Records!
</td>
</tr>
<?php
} // End of check result array
?>
</tbody>
</table>
这是替代解决方案。这不是100%正确,您需要调整它以使其正确。需要确保内部循环始终生成所需的行数。 这将创建行和[X]数量的单元格:
<?php
// Load data
$data = array();
while ($pF = mysql_fetch_array($stringVisits)) {
$data[] = $fF;
}
$profilesPerRow = 5;
for ($i = 0; $i < count($data); $i + $profilesPerRow) {
?>
<tr>
<?php
// Inner Loop, list profiles
for ($j = $i; $j < $profilesPerRow; $j++) {
$pF = $data[$i + $j];
$BuID = mysql_real_escape_string($pF['BuID']);
$getByInfo = mysql_query("SELECT * FROM users_profile WHERE uID = '$BuID'") or
die(mysql_error());
$getByProfile = mysql_fetch_array($getByInfo);
$getByInf = mysql_query("SELECT full_name, sex FROM users WHERE id = '$BuID'") or
die(mysql_error());
$getByProfil = mysql_fetch_array($getByInf);
$photo = !empty($getByProfile["photo_thumb"]) ? $getByProfile["photo_thumb"] : "noPhoto_thumb.jpg";
?>
<td class="viewercell" style="color: #CCC; font-size: 10px;">
<?php
echo "<a href='profil.php?id=$BuID'>";
echo "<img style='margin-right: 5px; width: 44px; height: 48px; border: 2px solid #FFF; ' src='images/profilePhoto/thumbs/$photo' />";
?>
</td>
<?php
} // End of inner loop
?>
</tr>
<?php
} // eND OF OUTER LOOP
?>
答案 1 :(得分:0)
一点也不清楚你要做什么。
如果$pF
的每个值都要产生多行,则需要将放在中。
答案 2 :(得分:-1)
把时间放在里面:
<?php
while(){
?>
<tr>
<td>
<?=info?>
</td>
</tr>
<?php
}// END While
?>