我正在尝试创建一个CMS,并且一直在观看关于创建一个的youtube教程,但是这个人遇到了很多麻烦,并没有真正回答有关人们所犯错误的问题,所以我一直有很多麻烦,基本上我正在尝试选择一个表格并在横幅下面显示页面的标题。
<?php
function confirm_query($result_set){
if (!$result_set){
die("unable to connect");
}
}
function get_info_by_id($information_id){
global $connection;
$query = "SELECT * FROM information WHERE id = $information_id LIMIT 1";
$result_set = mysql_query($query);
confirm_query($result_set);
if($info = mysql_fetch_array($result_set)){
return $info;
} else {
return NULL;
}
}
function get_page_by_id($page_id){
global $connection;
$query = "SELECT * FROM pages WHERE id = $page_id LIMIT 1";
$result_set = mysql_query($query);
confirm_query($result_set);
if($page = mysql_fetch_array($result_set)){
return $page;
} else {
return NULL;
}
}
?>
<?php
if (isset($_GET['information'])){
$sel_table1 = get_info_by_id($_GET['information']) or die ("Error executing get_info_by_id");
$sel_table2 = NULL;
$table2 = 0;
$table1 == $sel_table1;
echo ('IF statment of _GET is running');
} elseif (isset($_GET['pages'])){
$table1 = 0;
$sel_table2 = get_page_by_id($_GET['pages']) or die ("Error executing get_page_by_id");
$sel_table1 = NULL;
$table2 == $sel_table2;
echo ('Elseif statment of _GET is running');
} else {
$table1 = 0;
$sel_table1 = NULL;
$sel_table2 = NULL;
$table2 = 0;
echo ('Else statement of _GET is running');
}
?>
<?php
$query = "SELECT * FROM information ORDER BY position ASC" or die ("Error retrieving database");
$information_set = mysqli_query($connection, $query) or die ("Error retrieving
information_result");
while($info = mysqli_fetch_array($information_set)){
echo "<li ";
if ($info["id"] == $table1['id']){
echo "class = \"selected\"";
}
echo "><a href=\"content.php?info=" . urlencode($info["id"]) ."\">"
. $info['menu'] . "</a></li>";
$query = "SELECT * FROM pages WHERE information_id ={$info["id"]} ORDER BY position ASC" or die("Error retrieving database");
$page_set = mysqli_query($connection, $query) or die ("Error retrieving page_result");
echo "<ul class=\"pages\">";
while($page = mysqli_fetch_array($page_set)){
echo "<li ";
if ($page["id"] == $table2['id']){
echo "class = \"selected\"";
}
echo "><a href=\"content.php?page=" . urlencode($page["id"]) ."\">"
. $page['menu'] . "</a></li>";
}
echo "</ul>";
}
?>
</td>
<td id = 'main'>
<?php
if(!is_null($sel_table1)) { ?>
?>
<h2><?php echo $sel_table1['menu'] or die ("Unable to display sel_table1"); ?></h2>
<?php } elseif (!is_null($sel_table2)) { ?>
<h2><?php echo $sel_table2['menu'] or die ("Unable to display sel_table2"); ?></h2>
<div class = 'page-content'>
<?php
echo $sel_table2['content'];
?>
</div>
<?php } else { ?>
<h2> Select a menu from our Information table or Page table</h2>
<?php } ?>
每次我运行它时,它会从第一段代码中运行Else语句。请帮忙