gpt4 book ai didi

php - 在 PHP 中使变量成为全局变量?

转载 作者:太空宇宙 更新时间:2023-11-03 10:26:53 25 4
gpt4 key购买 nike

需要使 $courseInfo 和 $row 全局化,以便它们可用于打印标题 DIV 中的行详细信息。

不知道如何做到这一点。任何帮助都会很棒。

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

最佳答案

我认为它们已经是全局性的。 "PHP does not have a block-level scope."

关于php - 在 PHP 中使变量成为全局变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4770106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com