Reputation: 1067
I tried to allow the last td
in this code to be beside the previous td
, but I can't and the td
is printed in a new line. How to allow them to be beside each other,the problem is that the 1st 5 td
are in a foreach loop and the last td
is not follow this foreach as it's value is a function and not a key or a value in the foreach.
<?php foreach($downloads as $dl) { ?>
<tr id="this">
<td ><img src="images/<?=$dl['type']?>.png"/></td>
<td id="no3"><?=$dl['type']?></td>
<td>
<a target="_blank" style="margin-right:3px" href="download.php?id=<?=$dl['id']?>">
<?=$dl['title']?>
</a>
</td>
<td>
<center>
<a href="http://<?=urlencode($dl['surl'])?>"><?=$dl['sname']?></a>
</center>
</td>
<td align="center"><?=$dl['views']?></td>
</tr>
<?php } ?>
<td align="center"><?=$core->use_love(); ?></td>
The function of the last td
public function use_love(){
$sql=mysql_query("select * from wcddl_downloads ORDER BY id DESC LIMIT ".$this->pg.",".$this->limit."");
while($row=mysql_fetch_array($sql))
{
$down_id=$row['id'];
$love=$row['love'];
?>
<div class="box" align="center">
<a href="#" class="love" id="<?php echo $down_id; ?>">
<span class="on_img" align="left"> <?php echo $love; ?> </span>
</a>
</div>
<?
}
}
Upvotes: 4
Views: 1474
Reputation: 8969
UPDATE: I just saw you added a diagram. This answer now makes no sense as the text description given earlier has nothing to do with what you want to achieve in the diagram.
I submit the modification to Steve Nay's answer as you need the same number of TD
in all your TR
. When you don't have the same count, you need to use colspan
to achieve it. I've added a counter to check if it's the last time you loop. Here it goes:
<?php
$downloads_count = count($downloads);
$counter = 0;
foreach($downloads as $dl) :
$counter++;
// If this is the first time through the loop, don't echo a </tr> tag:
if ($counter > 1) {
echo "</tr>";
}
// Now print the new row, but don't close it yet:
?>
<tr id="this">
<td><img src="images/<?=$dl['type']?>.png"/></td>
<td id="no3"><?=$dl['type']?></td>
<td><a target="_blank" style="margin-right:3px" href="download.php?id=<?=$dl['id']?>"><?=$dl['title']?></a></td>
<td><center><a href="http://<?=urlencode($dl['surl'])?>"><?=$dl['sname']?></a></center></td>
<td align="center"<?php if ($downloads_count != $counter) echo ' colspan="2"'; ?>><?=$dl['views']?></td>
<?php endforeach; ?>
<td align="center"><?=$core->use_love(); ?></td>
</tr>
Upvotes: 1
Reputation: 2829
The last <td>
(the one outside the foreach
loop) is on a new line because it's outside the last <tr>
tag. One way to solve this is to always close the </tr>
tag after the last <td>
, like this:
<?php
$first_time = True;
foreach($downloads as $dl) {
// If this is the first time through the loop, don't echo a </tr> tag:
if ($first_time) {
$first_time = False;
} else {
echo "</tr>";
}
// Now print the new row, but don't close it yet:
?>
<tr id="this">
<td><img src="images/<?=$dl['type']?>.png"/></td>
<td id="no3"><?=$dl['type']?></td>
<td><a target="_blank" style="margin-right:3px" href="download.php?id=<?=$dl['id']?>"><?=$dl['title']?></a></td>
<td><center><a href="http://<?=urlencode($dl['surl'])?>"><?=$dl['sname']?></a></center></td>
<td align="center"><?=$dl['views']?></td>
<?php
}
?>
<td align="center"><?=$core->use_love(); ?></td>
</tr>
This will always put the last <td>
in the final row.
Upvotes: 1