来自2个php文件的数据库中的数据

时间:2016-01-29 09:28:10

标签: php html mysql

我有2个PHP文件。其中一个是运行大部分PHP代码的文件,另一个是显示HTML页面。

我想在我的第二个PHP页面上显示一些数据库信息(包含一些HTML)。问题是,我没有显示任何数据。

我尝试在数据库结果上使用print_r(),但这些仅显示在第一页上。

让我用我的代码解释自己:

第1页PHP页面(test.php)

// Class Initialization, DB connection etc.
require_once 'core/init.php';

// Create instance of class Subscription
$s = new Subscription();

// Get results from the DB
$sInfo = $s->get(Session::get('user'));
$sInfo = $s->data();

// When print_r() is ran here it shows the DB results
print_r($sInfo);

// Include the second PHP file
require_once VIEW_ROOT . '/general/test_view.php';

第二个PHP页面(test_view.php)

// Header file
<?php require_once VIEW_ROOT . '/templates/header.php'; ?>

// Main content
<div class="container">
    <div class="wrapper">
        // Checking if the DB information is an array, "is not array" is shown
        <?php if(is_array($sInfo)): ?>
        <p>Is array!</p>
        <?php else: ?>
        <p>Is not array</p>
        <?php endif; ?>
    </div>
</div>

// Footer file
<?php require_once VIEW_ROOT . '/templates/footer.php'; ?>

我的问题,为什么它不会在第二页上收到数据?

0 个答案:

没有答案