我已成功从一张表中提取所有必填字段 ['hotel' 是我的表名]。另外,我想同时从另一个表中提取一些字段 ['rates' 是另一个表名]。我该怎么做?
这是我的表“酒店”的工作代码:
<!--deal-->
<?php
$mysqli = new mysqli('localhost', 'root', '', 'swaminarayan');
if ($result = $mysqli->query("SELECT * FROM hotel")) {
$directory = "../administrator/images/hotels/";
while ($row = $result->fetch_assoc())
{?
<article class="one-fourth">
<figure>
<?php
$search_dir = "$directory/{$row['name']}{$row['hotel_address']}";
$images = glob("$search_dir/*.jpg");
sort($images);
//display images
//display random image
if (count($images) > 0) { // make sure at least one image exists
// Get a random index in the array with rand(min, max) which is inclusive
$randomImageIndex = rand(0, count($images)-1);
$img = $images[$randomImageIndex]; // random image
echo "<img src='$img' height='150' width='150' /> ";
}else {
// possibly display a placeholder image?
} ?
</figure>
<div class="details">
<h1><?php echo " ".$row['name']." ";?>
</h1>
<span class="price">Price per room per night from <em>$<?php echo " ".$row['defult_price']." ";?></em> </span> // This defult_price is not from table 'hotel', it is from table 'rates'
<div class="description">
<p><?php echo " ".$row['hotel_description']." ";?> <a href="<?php echo "".$row['hotel_address']."";?>.php">More info</a></p>
</div>
<a href="booking-step1.php" title="Book now" class="gradient-button">Book now</a>
</div>
</article><?php }}?>
<!--//deal-->
在上面,我想从 'rates' 表中提取房价字段并在此处显示{ 在这里:[<span class="price">Price per room per night from <em>$<?php echo " ".$row['default_price']." ";?></em> </span> }]
,这是来自表 'rates' 的唯一值,否则全部来自表 'hotel'。