tags:

views:

61

answers:

2

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!

+1  A: 

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>';
sunetos
To be more specific, it doesn't matter if there's an index or not, as anything in single quotes has literal output and doesn't parse variables. `'Some text $var more text'` just outputs exactly as it's written: Some text $var more text.
Zurahn
A: 

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>';
Mark Eirich
thanks for your help Mark Godbless!
devzone
No problem. I'm glad you found it helpful! If you actually used my answer, it would be awesome if you could mark my answer as accepted (this will increase your reputation points). Good luck on the project!
Mark Eirich