如何使用内连接显示?

时间:2017-01-23 06:56:02

标签: php html

我还在学习php,我有这两个代码

这是为了连接到数据库:

<?php
include 'C:/xampp/htdocs/lumino/function.php';
$link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);

if(!$link)
{die('Could not connect: ' . mysqli_error($link));}

$db_selected = mysqli_select_db($link, DB_NAME);

if (!$db_selected)
{die('Can\'t use ' . DB_NAME . ': ' . mysqli_error($link));}

$sql = "SELECT product_database.prod_id, product_database.prod_name, product_database.prod_year, product_database.prod_price, product_database.prod_desc, product_database.prod_comp, product_database.prod_shop, ctg_db.ctg_name, product_database.prod_attr, product_database.prod_tag 
        FROM product_database
        INNER JOIN ctg_db
        ON product_database.ctg_id = ctg_db.ctg_id";


$results = mysqli_query($link, $sql);

if(!$results)
{die('Invalid query: ' . mysqli_error($link));}

mysqli_close($link);
?>

这是为了查看数据:

<?php
        include 'C:/xampp/htdocs/lumino/func_view_item.php';
        echo '
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">Item List</div>
                    <div class="panel-body">    ';
                    echo"<table border = 3 >
                            <thead>
                            <tr>
                                <th>Product ID</th> 
                                <th>Product Name</th> 
                                <th>Year Produced</th> 
                                <th>Price</th> 
                                <th>Description</th> 
                                <th>Company</th> 
                                <th>Shop</th> 
                                <th>Category</th> 
                                <th>Attribute</th> 
                                <th>Tag</th>
                            </tr>
                            </thead>";
                            while($record = mysqli_fetch_array($results))
                                                {echo "<tbody>";
                                                    echo "<tr>";
                                                    echo "<td>". $record['prod_id'] . "</td>";
                                                    echo "<td>". $record['prod_name'] . "</td>";
                                                    echo "<td>". $record['prod_year'] . "</td>";
                                                    echo "<td>". $record['prod_price'] . "</td>";
                                                    echo "<td>". $record['prod_desc'] . "</td>";
                                                    echo "<td>". $record['prod_comp'] . "</td>";
                                                    echo "<td>". $record['prod_shop'] . "</td>";
                                                    echo "<td>". $record['ctg_name'] . "</td>";
                                                    echo "<td>". $record['prod_attr'] . "</td>";
                                                    echo "<td>". $record['prod_tag'] . "</td>";
                                                    echo "</tr>";
                                                echo "</tbody>";}
                                                echo '
                        </table>
                    </div>
                </div>
            </div>
        </div>' ; 
        ?>

视图功能似乎没有输出数据。 你能帮我显示数据库中的数据吗? 谢谢

0 个答案:

没有答案