Column next to each other

I tried to allow the last td in this code to be next to the previous td , but I can’t, and td is printed on a new line. How to allow them to be next to each other, the problem is that the first 5 td are in the foreach loop, and the last td does not follow this foreach, because this value is a function, not a key or value in 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> 

http://advphp.com/imgup/images/41553286204776144664.jpghttp://advphp.com/imgup/images/86639621977227017216.jpg

Last td function

  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> <? } } 
+4
source share
2 answers

The last <td> (outside the foreach ) is on the new line because it is outside the last <tr> . One way to resolve this issue is to always close the </tr> after the last <td> , for example:

 <?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 contain the last <td> in the last line.

+1
source

UPDATE: I just saw that you added a chart. This answer now makes no sense, since the text description above has nothing to do with what you want to achieve in the diagram.

I am sending the changes in response to Steve Nye, since you need the same amount of TD in all your TR . If you do not have one account, you need to use colspan to achieve it. I added a counter to check if it is the last time you loop. Here it is:

 <?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> 
+1
source

Source: https://habr.com/ru/post/1402458/


All Articles