开发者

PHP MYSQL, How to show records in four columns ,

Here is my code the records shows in four columns but if my records is blank it shows three balng images, any suggestions?

$query = mysql_query("SELECT * from rbf_events_images where event_id='".$_GET['id']."'");
echo '<table border="1">';
if(count(mysql_num_rows($query)>0)):
$tropentags='<tr>';
$troclosingtags='</tr>';
$formTags="";
$tdTags="";
$count=1;
while($row = mysql_fetch_array($query)){

$tdTags.='<td align="left" valign="middle" class="td" >$row['image']</td>';

if ($count>3)
    {
   $formTags.=$tropentags.$tdTags.$开发者_开发技巧troclosingtags;
   $tdTags="";
   $count=0;
    }
    $count=$count+1;
  }
if ($count>0)
{
  for($i = 1; $i <= (4-$count) ; $i++)
  {
$tdTags.='<td align="left" valign="middle" class="td"  >$row['image']</td>'; 
  }
  $formTags.=$tropentags.$tdTags.$troclosingtags;
}

echo $formTags;  


endif;

Thanks for your help!really appreciated!


I noticed that on lines like this one:

$tdTags.='<td align="left" valign="middle" class="td" >$row['image']</td>';

You are delimiting the string with single quotes ('), and you are also trying to embed a variable in the string that uses single quotes. I'm not sure how you did not get compile errors for that. I would switch to:

$tdTags= '<td align="left" valign="middle" class="td">' . $row['image'] . '</td>';


Here's what I usually do to put records in columns:

$id = mysql_real_escape_string($_GET['id']);
$query = mysql_query("SELECT * from rbf_events_images where event_id='$id'");
echo '<table border="1"><tbody><tr>';
if (mysql_num_rows($query) > 0) {
    $count = 0;
    while ($row = mysql_fetch_array($query)) {
        if ($count && $count % 4 == 0) echo '</tr><tr>';
        echo '<td align="left" valign="middle" class="td">'.$row['image'].'</td>';
        $count++;
    }
}
echo '</tr></tbody></table>';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜