Forum Moderators: coopster
Currently this is my set up:
$allowedPages = array("home", "about", "registration","contact");
$allowedPageTitles = array("Home","About","Registration","Contact");
$allowedPagesFull = array_combine($allowedPages1, $allowedPageTitles);
$pageName = NULL;
if (isset($_GET['pageSubmit'])) {
if (in_array($_GET['page'], $allowedPages)) {
$pageName = $_GET['page'];
}
}
The two separate arrays could just be one associative array since I'm combining them later. The arrays hold the html name and the visible name for each page.
Ideally I'd like to store those arrays in a table and somehow reference them via a query that lets me combine them into an associative array or something, like this (this code obviously doesn't work though:
$allowedPages = mysql_query("SELECT id_page, title FROM $tableName");
if (isset($_GET['pageSubmit'])) {
if (whatever the GET variable was is allowed by the $allowedpages query)) {
$pageName = $_GET['page'];
}
}
What's the best way to do this?
Thanks!
The arrays were my original workaround for the problem, not using any tables: I built the associative array from the two separate arrays for htmlname and realname:
$allowedPages = array("home", "about", "registration","contact");
$allowedPageTitles = array("Home","About","Registration","Contact");
$allowedPagesFull = array_combine($allowedPages, $allowedPageTitles);
And then I could use those arrays in my code, checking the GET value against them. If GET doesn't match anything in $allowedPages, the default page is shown, though
That only works for one page, though, which is why I want to get that info into a table, potentially structured like this:
¦id¦htmlname¦realname¦
¦1 ¦ home ¦ Home ¦
¦2 ¦ about ¦ About ¦
etc
This way, the users can add new pages--an easy CMS thing to do.
The only thing I can't figure out is how to check if the GET value that is passed is in that htmlname column. inarray doesn't seem to work looking in an array generated by mysql_fetch_array when I try something like this:
$allowedpages = mysql_fetch_array(mysql_query("SELECT htmlname FROM allowedpages"));
if (in_array($_GET['page'], $allowedPages)) {
$pageName = $_GET['page'];
} else {
$pageName = "home";
}
That doesn't work though. How can I check GET against the results of that one column?
Hopefully this makes more sense...
Thanks!
What would be the best way to create an array like "home => Home, about => About" from all the rows in the table? Is that the most efficient way to check the GET value or is there a better way to see if something is in the table?