dongwei1855 2010-11-08 21:18
浏览 83
已采纳

全局变量的问题

I have a problem with include pages in PHP. Picture shows what I want to do. I want to include in my index.php page horizontal and vertical menu. But now I can include only one of them. In global.php there are database name, password, and variable which define what language I'm using now. I included with all derictives: include, include_once, require, require_once. Nothing helps. What can you propose me to do? Thanx!

alt text

EDIT:

Here is my code:

Index.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 and makeVert.php identical except one read from db and shows rows and second cols

<?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);
}
?>
  • 写回答

3条回答 默认 最新

  • dpmpa26468 2010-11-08 21:21
    关注

    if horizonal_menu.php and vertical_menu.php are both including global.php, you should make sure both of them are using require_once. If that is the case, you shouldn't have any problems.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 根据以下文字信息,做EA模型图
  • ¥15 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥60 关机时蓝屏并显示KMODE_EXCEPTION_NOT_HANDLED,怎么修?
  • ¥66 如何制作支付宝扫码跳转到发红包界面