php:从db中的不同表中检索并显示数据

时间:2017-10-06 05:15:42

标签: php mysql

我的数据库中有两个tablesroomcategory)。 room表由room_idroom_nameroom_image组成。 category表格由category_idroom_idcategory_namecategory_image组成。

我的索引页面显示了3种类型的房间。当我选择单击房间时,每个房间都应显示3个不同的类别。但是,没有显示任何类别。

这是我的代码:

<?php
  $con = mysqli_connect("localhost","root","","homefurniture");

function getRoom(){

global $con;

$get_room = "select * from room";

$run_room = mysqli_query($con, $get_room);

while ($row_room = mysqli_fetch_array($run_room)){

    $room_id = $row_room['room_id'];
    $room_name = $row_room ['room_name'];
    $room_image = $row_room['room_image'];

echo "<div class='col-md-4 about-left'>


                <figure class='effect-bubba'>



                    <a href = 'category.php?room=$room_id'>
                   <img class='img-responsive' src='images/$room_image' alt=''/>
                    <figcaption>
                        <h2>$room_name</h2>

                    </figcaption>           
                </figure>
            </div>
    ";
    }
}

function getRoomCat(){

$room_id = $_SESSION['roomid'];
global $con; 

$get_room_cat = "select * from category where room_id='".$room_id."'";

$run_room_cat = mysqli_query($con, $get_room_cat); 
while($row_room_cat=mysqli_fetch_array($run_room_cat)){

$category_id = $row_room_cat['category_id'];
$room_id = $row_room_cat['room_id'];
$category_name = $row_room_cat['category_name'];
$category_image = $row_room_cat['category_image'];



    echo "
             <h1>$room_name</h1><p></p>
        <div class='about-top grid-1'>
            <div class='col-md-4 about-left'>
                <figure class='effect-bubba'>
                    <a href= 'product.php?pro_id=$pro_id'>
                    <img class='img-responsive' src='images/$category_image' alt=''/>
                    <figcaption>
                        <h4>$category_name</h4>

                    </figcaption>           
                </figure>
            </div>
            </div>
</div>
    ";
    }
}

0 个答案:

没有答案