我正在尝试使用两个查询获取数据。在第一个查询中,我从页面表中获取page_id。获取后,页面ID第二个查询正在运行。但是当我在第二个查询中传递第一个查询变量时,它就无法正常工作。
<?php
$getvideo = "select page_id from pages";
$resu = mysql_query($getvideo);
$i = 1;
while ($video = mysql_fetch_array($resu)){
$page_id = $video['page_id'];
}
$getvideo = "select * from pages where active='1' and page_category='What-we-do' and page_id='$page_id' order by add_date desc limit 7";
$resu = mysql_query($getvideo);
$i = 1;
while ($video = mysql_fetch_array($resu)) :
// print_r($video);
$videos = $video['image'];
$url = $video['url'];
$alt = $video['img_alt'];
$alt = $video['page_id'];
//echo $page_id = $video['page_id'];
echo $rel_blog = $video['rel_blog'];
?>
<div data-aos="fade-up" data-aos-delay="0" data-aos-duration="1000" data-aos-once="true" class="col-md-4 text-center">
<img src="<?= $SiteUrl; ?>upload/pages/<?= $videos ?>" alt="<?= $alt ?>" title="<?= $alt ?>" class="mx-auto" />
<h4 style="line-height:23px">
<?= $video['page_title']; ?></h4>
<p><?= $video['page_content']; ?></p>
</div>
<?php endwhile; ?>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
我找到了这个问题的答案。为了获取循环外的变量,我们必须在循环外定义空变量。这对我来说是完美的。
<?php
$getvideo = "select page_id from pages";
$resu = mysql_query($getvideo);
$page_id=""
$i = 1;
while ($video = mysql_fetch_array($resu)){
$page_id.= $video['page_id'];
}
$getvideo = "select * from pages where active='1' and page_category='What-we-do' and page_id='$page_id' order by add_date desc limit 7";
$resu = mysql_query($getvideo);
$i = 1;
while ($video = mysql_fetch_array($resu)) :
// print_r($video);
$videos = $video['image'];
$url = $video['url'];
$alt = $video['img_alt'];
$alt = $video['page_id'];
//echo $page_id = $video['page_id'];
echo $rel_blog = $video['rel_blog'];
?>
<div data-aos="fade-up" data-aos-delay="0" data-aos-duration="1000" data-aos-once="true" class="col-md-4 text-center">
<img src="<?= $SiteUrl; ?>upload/pages/<?= $videos ?>" alt="<?= $alt ?>" title="<?= $alt ?>" class="mx-auto" />
<h4 style="line-height:23px">
<?= $video['page_title']; ?></h4>
<p><?= $video['page_content']; ?></p>
</div>
<?php endwhile; ?>
</div>
</div>
</div>
</div>