PHP: while </tr>
i got a problem, where can i place my </tr>
so it shoul开发者_StackOverflowdnt get duplicated when its in a while?
<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>
I would like to close that <tr>
and start a new one, but how can i do that? If i just put in </tr>
under the above^ it will duplicate the </tr>
because its inside the while()
If i do it after closing }
the while, i can not use the while()
´s $pF anymore in my next tr.
I want to make a new tr for showing the username under the profilephoto above.
You can open and close tr inside of the while, open right when you enter the loop and close right before you exit the loop. See code below, should do the trick
<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>
This is alternative solution. It is not 100% correct, you will need to tweak it to make it a correct. Need to make sure that innter loop always generates needed # of rows. This will create row and [X] amount of cells:
<?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
?>
It's not at all clear what you're trying to do.
If each value of $pF
is to result in more than one row, you need to put that inside the while.
Put inside the while :
<?php
while(){
?>
<tr>
<td>
<?=info?>
</td>
</tr>
<?php
}// END While
?>
精彩评论