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

时间:2022-02-01 21:33:37

I wonder if I could get datas out of sql database within a php include..?

我想知道我是否可以从php包含的sql数据库中获取数据..?

Now I got:

现在我得到了:

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

I would like to get for example the foldername out of database... Why: I got hundreds of folders, so to include a certain file.php within the main frame I would have to realy write each foldername rather then getting the foldername out of the id of the customer.

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

something like:

<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>

I would like to draw the name of the costumer out of database via id... ... in the header section of the page I have:

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

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

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

I know that doesn't work, but I could not find how I could do a job like that ... Anybody know if thats possible...? Martin

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

3 个解决方案

#1


0  

You wouldn't echo the variable as that is displayed after the execute, you would store the path in a variable then do the require withe the variable as the parameter.

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

#2


0  

You may try making the file name before the include and then use the include:

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

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

#3


0  

Of cource you can, if you already know folder name. Something like this should work

如果您已经知道文件夹名称,您可以使用cource。这样的事情应该有效

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

#1


0  

You wouldn't echo the variable as that is displayed after the execute, you would store the path in a variable then do the require withe the variable as the parameter.

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

#2


0  

You may try making the file name before the include and then use the include:

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

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

#3


0  

Of cource you can, if you already know folder name. Something like this should work

如果您已经知道文件夹名称,您可以使用cource。这样的事情应该有效

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