<div class="section" id="section2">
<div class="slide" id="slide1">
<div class="box">
<div class="haha1">Library</div>
<p>
<table class="box1" width="700" border="1">
<?php
$cnt= 0;
$nThumbXRow =5 ;
$sql = ("SELECT * FROM bookstore");
$result = mysql_query($sql);
while($row =mysql_fetch_array($result)){
if ($cnt%$nThumbXRow == 0){
echo "<tr>";
}
echo "<td><img src='" . $row['image'] .
"' height='250' width='150'><br />" .
$row['bookname'] ."<br />" .
$row['author'] .
" <br /><input type='submit' name='add'
value='Add Cart'></td>";
$cnt++;
if ($cnt%$nThumbXRow == 0){
echo "</tr><!-- row ending here -->";
}
}
?>
</table>
<br>
<center>Page 1</center>
</div></div>
<?php
$sql = ("SELECT * FROM bookstore");
$result = mysql_query($sql);
while($row =mysql_fetch_array($result))
{
?>
<table class="box1" width="700" border="1">
<tr>
<td><img src="<?php echo $row['image']; ?>" height="250" width="150"><br>
<?php echo $row['bookname']; ?><br>
<?php echo $row['author']; ?><br>
<input type="submit" name="add" value="Add Cart"></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<?php } ?>
这是我的表格,当我垂直添加新项目列表但我希望数组项目水平示例[item1,item2,item3,item4]之后,数组4项水平只创建另一个td
然后再次水平数组4次
必填项:
{1,2,3,4}
{5,6,7,8}
从左到右的数组
else数组垂直{1,5} {2,6},{3,7],[4,8]
答案 0 :(得分:0)
尝试以这种方式更改表格
<table class="box1" width="700" border="1">
<?php
$cnt= 0;
$nThumbXRow =5 ;
$sql = ("SELECT * FROM bookstore");
$result = mysql_query($sql);
while($row =mysql_fetch_array($result)){
if ($cnt%$nThumbXRow == 0){
echo "<tr>";
}
echo "<td><img src='" . $row['image'] .
"' height='250' width='150'><br />" .
$row['bookname'] ."<br />" .
$row['author'] .
" <br /><input type='submit' name='add'
value='Add Cart'></td>";
$cnt++;
if ($cnt%$nThumbXRow == 0){
echo "</tr><!-- row ending here -->";
}
}
?>
</table>
用于测试echo尝试这样一个简单的情况(只有按钮)
echo "<td><input type='submit' name='add'
value='Add Cart'></td>";
在这个示例中(我没有你对你的IMG进行db,所以我用字符串值更改了var值,你可以在第一行中看到2行pic 4,在第二行中看到2行。
然后,如果您没有获得相同的结果,那么您的选择或价值可能会有问题。
<table class="box1" width="700" border="1">
<?php
$cnt= 0;
$nThumbXRow =4 ;
$book = 0;
/* $sql = ("SELECT * FROM bookstore");
$result = mysql_query($sql);
while($row =mysql_fetch_array($result)){*/
while( $book<=5 ){
if ($cnt%$nThumbXRow == 0){
echo "<tr>";
}
/* echo "<td><img src='" . $row['image'] .
"' height='250' width='150'><br />" .
$row['bookname'] ."<br />" .
$row['author'] .
" <br /><input type='submit' name='add'
value='Add Cart'></td>";*/
echo "<td><img src='" . "row['image']" .
"' height='250' width='150'><br />" ."row['bookname']<br />" . "row['author']<br />" . "<input type='submit' name='add'
value='Add Cart'></td>";
$cnt++;
if ($cnt%$nThumbXRow == 0){
echo "</tr><!-- row ending here -->";
}
$book++;
}
?>
</table>