【发布时间】:2010-11-08 21:18:26
【问题描述】:
我在 PHP 中遇到了包含页面的问题。图片显示了我想做的事情。我想在我的 index.php 页面中包含水平和垂直菜单。但现在我只能包括其中之一。在 global.php 中有数据库名称、密码和变量,它们定义了我现在使用的语言。 我包含了所有的衍生词:include、include_once、require、require_once。没有什么帮助。你能建议我做什么?谢谢!
编辑:
这是我的代码:
索引.php:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>KUSS</title>
<link href="styles/default.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" class="main_border">
<?php
include_once ("modules/php/mainMenu.php");
?>
<? include_once ("modules/php/vertMenu.php"); ?><!--Head-->
</table>
</body>
</html>
global.php
<?php
// All global variables MUST be defines here
//representing current language
$gl_Lang = "UKR";
//current horizontal menu click
$gl_MaimMenuChoice;
//current vertical sub menu click
$gl_SubMenuChoice;
$gl_dbName = "127.0.0.1";
$gl_UserName = "user1";
$gl_Password = "12345";
$gl_adminDatabase = "admin";
?>
makeHoriz.php 和 makeVert.php 相同,除了一个从 db 读取并显示行和第二个列
<?php
function MakeLeftVMenu($tableName, $levelID, $parentName)
{
include_once ("modules/php/globals.php");
//connect to db or die)
$db = mysql_connect($gl_dbName, $gl_UserName, $gl_Password ) or die ("Unable to connect");
//to prevenr ????? symbols in unicode - utf-8 coding
mysql_query("SET NAMES 'UTF8'");
//select database
mysql_select_db($gl_adminDatabase, $db);
$sql = "SELECT " .$gl_Lang. ", Link FROM ". $tableName." WHERE LevelID = ".$levelID. " AND ParentName = '". $parentName."'";
echo $sql;
//execute SQL-query
$result = mysql_query($sql, $db);
//read data to array
$myRow = mysql_fetch_array($result);
//print it to screen into the table
do
{
echo "<tr><h3><a href=".trim($myRow['Link']).">". trim($myRow[$gl_Lang]) ."</a></h3></tr>";
}while($myRow = mysql_fetch_array($result));
//close database = very inportant
mysql_close($db);
}
?>
【问题讨论】:
-
同时包含两者时你看到了什么错误?
-
天哪,图片! +2 按钮在哪里?
-
+无穷大,拍出超棒的照片!
-
@porcupine:而不是图片 - 一些代码和文件结构会更好。也许你打错了,或者文件不存在。
-
另一方面,不要混淆为全局变量的标签,因为 php 中有一个全局变量类型。
标签: php include global-variables