我正在动态填充数据库中的内容提取表。
此表位于<div>
所以我设置一个变量$col
来限制我想要每行(by default I saw 5 fit perfectly) in the div
的列数。否则表格内容就会超出div。
问题是我必须手动设置。我环顾了很多如何在div内部制作任何内容,一旦它与边界相关但却找不到任何东西。如果我可以在不使用表格的情况下获得相同的结果,我认为这是问题。我很乐意更新。
$col = 1; //initialisation
foreach ($result as $product){ //a loop to fetch data into product object
if($product->visible == 1){
if($Col < 6){
echo "<td>";
echo "<a href ='read.php?id=".$product->id_product."&p=0'><div class='productdiv'>";
echo "<img src ='galleries/".$product->id_product."/c".$product->id_product.".jpg' alt = 'cover' width='220' height='300'><h4 class='productclass'>".$product->name_product."</h4>";
echo "</div></a>";
echo "</td>";
$col= $col+ 1; //here I'm incrementing
}
else{ //I close the line <tr> then another line begin
echo "</tr><tr><td>";
echo "<a href ='read.php?id=".$product->id_hentai."&p=0'><div class='hendiv'>";
echo "<img src ='galleries/".$product->id_product."/c".$product->id_product.".jpg' alt = 'cover' width='220' height='300'><h4 class='productclass'>".$product->name_product."</h4>";
echo "</div></a>";
echo "</td>";
$col= 1;
}//end the code
答案 0 :(得分:1)
请使用
display: inline-block
它将容纳内容。您在&#34; <tr>
&#34;中打开if
的位置条件。
答案 1 :(得分:0)
不完全确定我理解你的问题,但这听起来像JS的工作
1您应该从db读取所有可能的列并从中创建表,但将可见性设置为隐藏。
2然后添加JS并定义列优先级。
3获取表格的最大允许宽度。
4使用所有单元格的JS读取宽度
5优先级将您的单元格宽度相加,直到它为&gt;最大宽度
6隐藏不太适合的优先级
的单元格