你可以循环吗?来自不同表的单个while语句中有2个循环?

时间:2018-03-08 03:14:06

标签: php

我试图从同一个数据库循环2个不同的表并同时显示它。我的问题是,你可以在一个while语句中循环2个不同的行吗?

<?php 

$sql = "SELECT remaining from budget";
$result = mysqli_query($con,$sql); 
$sql2 = "SELECT SUM(cost) as costTotal from project";   
$result2 = mysqli_query($con,$sql2); 

while($row = mysqli_fetch_array($result) && $row2 = mysqli_fetch_array($result2)){?>

<span id='remain'><?php echo "$row2[costTotal]"; ?></span>
<span id='text'> <?php echo "$row[remaining]"; ?></span>
<?php } ?>

0 个答案:

没有答案