我可以从php include中的数据库中获取数据吗?

时间:2014-08-08 15:05:09

标签: php mysql sql database include

我想知道我是否可以在php include中从sql数据库中获取数据..?

现在我得到了:

<?php include ("../foldername-Mark/file.php"); ?>

我想从数据库中获取foldername ... 为什么: 我有数百个文件夹,所以要在主框架中包含一个file.php 我必须真正地编写每个foldername而不是从客户的id中获取foldername。

类似的东西:

<div id="header"> <?php include ("header.php"); ?> </div>

<div id="individual-content"> 
<?php include ("customers/name-of-customer/contend.php"); ?> </div>

<div id="footer"> <?php include ("footer.php"); ?> </div>

我想通过id从数据库中绘制出客户的名字... ... 在页面的标题部分我有:

$query_Recordset7 = "SELECT * FROM apartments WHERE apartments_london.id=96";

<?php include ("../  **<?php echo $row_Recordset7['Foldername']; ?>**   /file.php"); ?>

我知道这不起作用,但我找不到如何做这样的工作...... 有人知道这是否可能......? 马丁

3 个答案:

答案 0 :(得分:0)

当然,如果你已经知道文件夹名称,你可以。 这样的事情应该有效

// Retrieve row from database into $row_Record7 before building path
$path = "../{$row_Record7[Foldername]}/file.php";
include($path);

答案 1 :(得分:0)

您可以尝试在include之前创建文件名,然后使用include

$filename = '../' . $row_Recordset7['Foldername'] . '/file.php';
include $filename;

答案 2 :(得分:0)

你不会在执行后显示回显变量,你会将路径存储在一个变量中,然后以变量作为参数来执行。