Hejsa
Jeg er ved at lave noget simpelt CMS til en hjemmeside. På denne "bagdør" opererer jeg med:
pageid: Hvilken tabel i min MySQL base der skal ses/tilføjes/rettes osv.
plugid: Hvilket af mine "plug ins" der skal includes på index.php for at udføre en af disse opgaver
id: Hvilken "record" i MySQL basen der er tale om.
Min pageid bliver trukket med rundt i de forskellige plugins, og således også med tilbage til "forsiden". (index.php, pageid=0). Problemet er bare, at pageid bliver til 3 efter at have været inde i mit "view plug in" anden gang (!). Jeg har MYREkneppet koden, og kan ikke se hvorfor det sker.
Det pudsige er, at min URL i browseren siger pageid=0, men mine links viser pageid=3 - dette til trods for at den henter pageid på en $_GET.
Min index.php
<?php
// CALL SETTINGS
include("scripts/settings.php");
// CALL HTML FUNCTIONS
require("scripts/html_functions.php");
// SET HTML FUNCTIONS
$begin_html = begin_html("$name", "$path");
$end_html = end_html();
$pagetop_start = pagetop_start("$path", "$width", "$head_height", "$header", "$align");
$pagetop_end = pagetop_end();
$main_content_start = main_content_start("$path", "$width", "$bg_repeat", "$align");
$main_content_end = main_content_end();
$footer = footer("$path", "$width", "$footer_img", "$footer_height", "$align");
// BUILD HTML STRUCTURE
echo $begin_html;
echo $pagetop_start;
// INSERT TITLE
echo "<div id=\\"titlebar\\">";
echo "<h1>ADMINISTRATION</h1>";
echo "</div>";
echo $pagetop_end;
// BUILD MAINCONTENT
echo $main_content_start;
include("scripts/menu.php");
echo "</div>";
echo "<div id=\\"maincontent\\">";
// WHICH PLUGIN?
if ($_GET[plugid] == 1) {
include("../admin/plugins/plug_view.php");
}
elseif ($_GET[plugid] == 2) {
include("../admin/plugins/plug_add.php");
}
elseif ($_GET[plugid] == 3) {
include("../admin/plugins/plug_edit.php");
}
elseif ($_GET[plugid] == 4) {
include("../admin/plugins/plug_mysql.php");
}
elseif ($_GET[plugid] == 5) {
include("../admin/plugins/plug_delete.php");
}
else
include("../admin/plugins/plug_list.php");
echo "</div>";
// END PAGE
echo $main_content_end;
echo $footer;
echo $end_html;
?>
Mit plugin 1 (view)
<?php
require("../scripts/connect_db.php");
$id = $_GET['id'];
$pageid = $_GET['pageid'];
$row = mysql_fetch_array(mysql_query("SELECT * FROM textpages WHERE id = '$id'"));
$title = $row['title'];
$body = $row['text'];
$body = nl2br($body);
echo "<div class=\\"textbox\\">";
echo "<h1>$title</h1><br>";
echo "<p>$body</p>";
echo "</div><br>";
include("../scripts/close_db.php");
echo "<p><a href=\\"index.php?pageid=".$pageid."\\">[ Tilbage ]</a>";
echo "<a href=\\"index.php?pageid=".$pageid."&plugid=3&id=$id\\"> [ Rediger ]</a></p>";
?>
Mit plugin 0 (list)
<?php
// CONNENCT TO DATABASE
require("../scripts/connect_db.php");
// PAGE ID
if($_GET['pageid'] == "0") {
$database = "textpages";
$maintitle = "TEKSTSIDER";
$rowtitle = "title";
}
elseif($_GET['pageid'] == "1") {
$database = "movies";
$maintitle = "WEBUDSTILLINGER";
$rowtitle = "title";
}
elseif($_GET['pageid'] == "2") {
$database = "missing";
$maintitle = "EFTERLYSNINGER";
$rowtitle = "case";
}
elseif($_GET['pageid'] == "3") {
$database = "links";
$maintitle = "LINKS";
$rowtitle = "link_name";
}
elseif(!$_GET['pageid']) {
$pageid = "0";
$database = "textpages";
$maintitle = "TEKSTSIDER";
$rowtitle = "title";
}
// GET DATA
$sql = mysql_query("SELECT * FROM $database");
// TEXTPAGE VIEW TABLE
echo "<table width=\\"566\\" border=\\"0\\" cellspacing=\\"0\\" cellpadding=\\"1\\">";
echo "<tr><td colspan=\\"4\\" align=\\"left\\" valign=\\"top\\"><h1>$maintitle</h1><br><br></td></tr>";
while ($row = mysql_fetch_array($sql)) {
if (strlen($row[$rowtitle]) > 55) {
$title = substr($row[$rowtitle], 0, 55) . "...";
} elseif ($row[$rowtitle] == "") {
$title = "-";
} else {
$title = $row[$rowtitle];
}
echo "<tr>";
echo "<td width=\\"85%\\" align=\\"left\\" valign=\\"top\\"><div class=\\"textbox\\"><a href=\\"index.php?pageid=".$pageid."&plugid=1&id=".$row['id']."\\">$title</a></div></td>";
echo "<td colspan=\\"2\\" width=\\"15%\\" align=\\"center\\" valign=\\"top\\"><div class=\\"textbox\\"><a href=\\"index.php?pageid=".$pageid."&plugid=3&id=".$row['id']."\\">Rediger</a></div></td>";
echo "</tr>";
}
echo "<tr>";
echo "<td colspan=\\"4\\" align=\\"center\\" valign=\\"top\\"><br><p><a href=\\"#top\\">[ TIL TOPPEN ]</a></p></td>";
echo "</tr>";
echo "</table>";
include("../scripts/close_db.php");
?>
Håber på et falkeblik
Mvh
Gunnar