So I taught myself some basic PHP stuff and wrote a script for my site to run from one file and some stuff I put into my SQL server. (I'm still working on the interface to edit my site without PHPMyAdmin.) Anyway, I wanted your opinions on two pieces of code and your help with another that I'm trying to do. Here's the bulk of the PHP; it goes at the top of the file and I was wondering if I did it efficiently or if there's a better way to achieve what I'm intending:
The navigation links are an href that goes "?a=areaname", so that's why I used the GET server info. And then to write the body:Code:<?php // calliander.net main php script
/* Initiate a connection to the SQL server. */
$sqlconn = @mysql_connect("mysqlserver","myusername","mypassword") or die(require("error.html"));
/* Select the appropriate database. */
$dbselect = @mysql_select_db("mydb",$sqlconn) or die(require("error.html"));
/* Get the data from the table. */
$myquery = @mysql_query("select * from site_vars",$sqlconn) or die(require("error.html"));
/* Parse the data from the query. */
while($row = mysql_fetch_array($myquery)) {
$site_css = $row["vars_css"];
$site_tagline = $row["vars_tagline"];
}
/* Obtain the GET information. */
$sitearea = $_GET['a'];
if (!$sitearea) {
$sitearea = "home";
}
/* Set up for main body display below. */
$table = "site_$sitearea";
$bodyquery = @mysql_query("select * from $table",$sqlconn) or die(require("error.html"));
?>
And my question is something that looks like it should work, but doesn't - I want to have PHP build my navigation links. There's two images - the ones with blue letters for links and grey letters for ones that aren't (because you're already there). I wrote a script that goes like this:Code:<?php // main body loader
while($row = mysql_fetch_array($bodyquery)) {
if ($row[0]) {
echo("\t<div class=\"header\">");
echo($row[0]);
echo($row[1]);
echo("</div>\n");
}
echo("\t<div class=\"paragraph\">");
echo($row[2]);
echo("</div>\n");
}
?>
I'm not sure why it isn't working, but any help is appreciated. Thanks in advance. You can see the site in action at http://www.calliander.net/ (though, I'm still building the pages). When SQL is broken, the die(require.. presents http://www.calliander.net/error.htmlCode:<?php // navigation links builder
if ($sitearea = "home") {
echo(text for home with grey and no link);
} else {
echo(text for home link);
}
?>
