需要製作$ courseInfo和$ row global,以便它們可用於在標題DIV中打印行詳細信息。在PHP中使變量全局化?
沒有線索如何做到這一點。任何幫助都會很棒。
<?php
// Get Course ID From Link
$ID = mysql_real_escape_string($_REQUEST['ID']);
// Check the Course ID exists
$courseCheck = mysql_query("SELECT * FROM Courses WHERE CourseID = '".$ID."'");
if (mysql_num_rows($courseCheck) == 1) {
$checkMember = mysql_query("SELECT * FROM CourseMembers WHERE CourseID = '".$ID."' AND UserID = '".$_SESSION['UserID']."'");
if (mysql_num_rows($checkMember) == 1) {
?>
<html>
<head>
<!-- Style Sheets -->
<link rel="stylesheet" href="style/reset.css" type="text/css" media=screen />
<link rel="stylesheet" href="style/style.css" type="text/css" media=screen />
</head>
<body>
<?php
if ($_SESSION['LoggedIn'] == 1){
$courseInfo = mysql_query("SELECT * FROM Courses WHERE CourseID = '".$ID."'");
$row = mysql_fetch_assoc($courseInfo);
?>
<div id="container">
<div id="side">
<?php include("lib/sidebar.php"); ?>
</div>
<div id="main">
<div id="mainbox">
<div id="header"><b><?php echo $row['CourseName']; ?></b></div>
<p>Hello world, this is a test.</p>
</div>
</div>
</div>
<div class="clear"></div>
<?php
}
else {
echo "Not logged in.";
}
}
else {
echo "You are not a member of this Course";
}
}
else {
echo "No Course Found";
}
?>
</body>
http://php.net/manual/en/language.variables.scope.php – marcog 2011-01-22 19:40:56
如果$ _SESSION [ '的loggedIn'] == 1出現故障,他們$ courseInfo和$ row永遠不會被創建。順便說一句,你不應該像這樣混合使用PHP和HTML。由於歷史原因,PHP只允許這樣做。沒有人再那樣做了。你需要學習如何正確構建一個PHP程序。閱讀蛋糕PHP和zend框架。 – Jay 2011-01-22 19:54:48