This is a little awkward to explain but i'll try my best!
<?php /* +------------------------------------------------------------------------------- | pages.php | ==== | Grabs the content for and sets up our pages and navigations. | ---- | Written: 1 Jan 2009 ~ Caleb | # Page names and links gotten from DB and parsed into <li></li> tags +------------------------------------------------------------------------------- */ // Load up our Global Vars, functions and connect to the database require ('global.php'); require ('functions.php'); dbconnect(); // First job is to get the page names so we can build our navigation links /* We then write it into the function nav_page_names (); to call in the template later on */ function nav_page_names() { $page_nav_query = "SELECT name, link FROM pages ORDER BY id ASC"; $page_nav_result = mysql_query($page_nav_query); while($row = mysql_fetch_array($page_nav_result, MYSQL_ASSOC)) echo "<li><a href=\".$homepage./{$row['link']}\">{$row['name']}</a></li>"; } ### Now to make some pages ### // First, we have to figure out what page is being requested if (isset($_GET["page"])) { $page_url_get = $_GET["page"]; if ($page_url_get == "") // If no page is being requested we set the $show_homepage var to true for later use $show_homepage = "true"; } else { $show_homepage = "true"; } $page_url_query = "SELECT link FROM pages ORDER BY id ASC"; // Get the data from the link row. We're going to compare the url we've got with the id's in 'link' $page_url_result = mysql_query($page_url_query); while($row = mysql_fetch_array($page_url_result, MYSQL_ASSOC)) if ($row['link'] == $page_url_result){ echo "Yes"; // This will be modified to show the actual data from the sql table once other problems have been resolved } elseif ($show_homepage = "true"){ $content = "This is the homepage"; // This will be modified to reflect the data for 'homepage' in the DB later } echo $content; ?>
In the database I have a table called 'pages', with the rows 'id, 'name', 'link', 'date' and 'content'. Name is just a name of it sort of thing like 'About Us' and link is the link version of that name 'aboutus'.
Now i'm not sure if the approach i have used with the (isset($_GET is even the right idea here and will almost definitely require tweaking later on anyway. The point i'm particularly struggling with here is "
if ($row['link'] == $page_url_result){ ". Obviously i'm saying does the isset GEt in the adress bar match the results of the query for the link row. That's fine (I think), the problem is that I have no idea how to compare it one at a time with each record in the row. Naturally it's not ever going to work this way if you compare it with all the records in the row at once. But how do you tell it to check each 'link' record one at a time to see if a suitable match is found there?
All help is appreciated, please pick apart my code and tell me how useless I really am at this