PHP试图通过id获取名称
谁能看看我的密码吗?我不知道他怎么了。 我正试图通过产品的id来获取city表的id。 while循环$product部分出现了一些问题,无法正常工作PHP试图通过id获取名称,php,mysqli,Php,Mysqli,谁能看看我的密码吗?我不知道他怎么了。 我正试图通过产品的id来获取city表的id。 while循环$product部分出现了一些问题,无法正常工作 <?php if( $result->num_rows > 0 ) { while ( $product = $result->fetch_assoc() ) { ?> <li class="accordion-item" data-accordion-item&
<?php
if( $result->num_rows > 0 ) {
while ( $product = $result->fetch_assoc() ) { ?>
<li class="accordion-item" data-accordion-item>
<a href="#" class="accordion-title">
<?php echo $product['product_name']; ?>
</a>
<div class="accordion-content" data-tab-content>
<table>
<thead>
<tr>
<th>price</th>
<th>description</th>
<th>city</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<?php echo $product['product_price']; ?>
</td>
<td>
<?php echo $product['product_desc']; ?>
</td>
**/////////this part is not working**
<?php
while ($city = $cities->fetch_assoc()){
if($city['id']==$product['city_id']) { ?>
<td>
<?php echo $city['city_name'];} ?>
</td>
<?php
</tr>
</tbody>
</table>
</div>
</li>
<?php
}
} else {
?>
<div class="alert alert-danger" role="alert">
NO CATEGORY FOUND!
</div>
<?php
}
?>
代码中存在语法错误。在关闭之前关闭if,这将导致html中断。请尝试此代码
<?php
while ($city = $cities->fetch_assoc()){
if($city['id']==$product['city_id']) {
?>
<td> <?php echo $city['city_name']; ?> </td>
<?php
}
}
?>
按$cities??id和cityname列出的数据类型是什么?这是从哪里得到的$cities->fetch_assoc您得到的结果是什么?$cities=$mysqli->query SELECT*FROM cities;问题在这里:。