我想每个采访下面有18个采访和一个按钮。但是我搞砸了周期,现在我每次采访下面有18个采访18个按钮。它应该只是一个按钮。PHP虽然周期
我几乎肯定它是一个循环问题。你能告诉我我的错误在哪里吗?
这里是我的代码:
<?php
$sql = "SELECT * FROM interviews WHERE featured = 1";
$featured = $db->query($sql);
?>
<div class="container">
<table class="rwd-table">
<tbody>
<br><br>
<tr>
<?php
include_once("../forum/connect.php");
$sql = "SELECT * FROM categories2 ORDER BY category ASC";
$res = mysql_query($sql) or die(mysql_error());
$interviews = "";
if(mysql_num_rows($res) > 0){
while($row = mysql_fetch_assoc($res)){
$id = $row['id'];
$category = $row['category'];
$sql2 = "SELECT * FROM interviews WHERE categories='".$id."'ORDER BY title DESC";
$res2 = mysql_query($sql2) or die(mysql_error());
if(mysql_num_rows($res2) > 0){
while($row2 = mysql_fetch_assoc($res2)){
$tid = $row2['id'];
$title = $row2['title'];
$interviews .= "<a href='view_interview.php?cid=".$id."&tid=".$tid."' class='cat_links'>".$category." - ".$title."</a>";
}
}
}
$counter = 0;
while($product = mysqli_fetch_assoc($featured)){
$image = $product['image'];
$title = $product['title'];
$decs = $product['description'];
if($counter % 3 == 0){
echo '</tr><tr>';
}
++$counter;
echo "<td>
<div id='element1'></div>
<div id='content1'>
<img src=".$image." alt=".$title.">
<h3>".$title."</h3>
<hr>
<h4>".$decs."</h4>
<div id='hovers'>
<a href='view_interview.php?cid=".$id."&tid=".$tid."' class='button' target='_blank'>
<span class='contentbut'> Read More</span>
</a>
</div>"; echo $interviews;
}
?>
<br><br>
</td>
<?php
}
?>
</tr>
</tbody>
</table>
</div>
*有18个采访,下面的每个采访的按钮。但我搞砸了周期,现在我有18次采访,每次采访下有18个按钮*。你的陈述是矛盾的。 – Ravi
我的意思是每次面试时应该只有一个按钮。换句话说,我需要18个采访和18个按钮。 – Kaloyan
但是现在,我在每次采访下面有18次采访和18次按钮。这意味着18 * 18 = 324个按钮。 – Kaloyan