您可以通过在变量的帮助下将变量从一个页面传递到另一个页面(about.php)来实现GET
。参考这个。
您也可以通过会话变量将数组(由菜单和页面链接组成)传递到另一个页面(比如 about.php)来实现。
<?php
// begin the session
session_start();
// populate the array with menus or populate the array with the item that you want to pass to next(say about.php) page
$my_array=array('home','about','gallery');
// put the array in a session variable
$_SESSION['mymenu']=$my_array;
?>
在about.php页面中
<?php
// begin the session
session_start();
// loop through the session array with foreach
foreach($_SESSION['mymenu'] as $key=>$value)
{
// and print the menu
echo $value.' <br />';
}
?>
UPD:我修改了你的代码。
<?php
session_start();
include('testconnect.php');
//calling menu from database
$query_sql = "SELECT * FROM meni";
$item_query = mysql_query($query_sql) or die(mysql_error());
$rsitem = mysql_fetch_assoc($item_query);
?>
<! DOCTYPE html>
<html>
<head><title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<link rel="stylesheet" href="style2.css" type="text/css" />
</head>
<body>
<nav>
<ul>
<?php
$idx=0;
do {
?>
<li><a href="menutest.php?meni_ID=<?php echo $rsitem['meni_ID']; ?>"><?php echo $rsitem['item']; ?></a></li>
<?php
$meni_ID_ARR[$idx]= $rsitem['meni_ID'];
$item_ARR[$idx]=$rsitem['item'];
$idx++;
}while ($rsitem = mysql_fetch_assoc($item_query));
// put the array in a session variable
$_SESSION['meni_ID_ARR_SESS']=$meni_ID_ARR;
$_SESSION['item_ARR_SESS']=$item_ARR;
?>
</ul>
</nav>
</body>
</html>
-
/*printing menu in about.php page*/
<?php
session_start();
?>
<?
if(isset($_SESSION['meni_ID_ARR_SESS']) && isset($_SESSION['item_ARR_SESS']))
{
$meniIDS=$_SESSION['meni_ID_ARR_SESS'];
$meniITEM=$_SESSION['item_ARR_SESS'];
for($idx=0;$idx<count($_SESSION['meni_ID_ARR_SESS']);$idx++)
{
echo '<li><a href="menutest.php?meni_ID='.$meniIDS[$idx].' ">' .$meniITEM[$idx].'</a></li>';
}
}
else
{
echo "Session not set!";
exit;
}
?>