我有一个包含从 database(news) 读取的信息的框,但我有另一个包含该框类别的数据库(categories)。如果类别是 7,我想自动制作 7 个框。
<?php
mysql_connect("localhost", "root","") or die(mysql_error());
mysql_select_db("tnews2") or die(mysql_error());
mysql_query("set names 'utf8'");
$rowsPerPage = 2;
$query1 = "SELECT id,name FROM categories ORDER BY ID";
$result1 = mysql_query($query1) or die(mysql_error()."[".$query1."]");
$query2 = "SELECT id,name,text,img,cat_id FROM news WHERE cat_id=2 ORDER BY ID DESC LIMIT $rowsPerPage";
$result2 = mysql_query($query2) or die(mysql_error()."[".$query2."]");
?>
while($row = mysql_fetch_array($result1)){ ?>
<?php for($i=0; $i<$row['id']; $i++){ ?>
<div class="focusBussines" >
<?php while ($rowB = mysql_fetch_array($result2)){ ?>
<a class="titleMini" href="categories.php?id=<?= $rowB['id'] ?>&cat_id=<?=$rowB['cat_id']?>">Бизнес</a>
<?php } ?>
<table class="table" width="100%">
<?php while ($rowB2 = mysql_fetch_array($result2)){
if($rowB2['cat_id'] == 2){ ?>
<tr>
<td align="left" width="150" >
<img class="pic" src="<?php echo $rowB2["img"];?>" height="120" width="120">
</td>
<td align="left" colspan="100%" id="title" ><a id="Zaglavie" href="novina.php?id=<?= $rowB2['id'] ?>&cat_id=<?=$rowB2['cat_id']?>" > <?php echo $rowB2['name']; ?></a></td>
</tr>
<tr >
<td colspan="100%"><hr/> </td>
</tr>
<?php } } ?>
</table>
</div>
<?php } } ?>
但它不起作用。