Hi Dagon
thanks for getting back. I actually tried that by creating a variable
$active = $_GET['catid'];
But I always get an "Undefined Index error. When I use that. I think it is because the current page is where I'm trying to get this to work is loaded by another variable from a different query further up the page. The link I want highlighted is just part of a list of links in the footer menu. I'm thinking I may have to rewrite the sql to do a join of some type. Then try to grab the catid.
But before I do that, this here seems to work but it works backwards.
The first link list item is always highlighted but its the wrong one. I have taken the liberty of posting the entire php code I'm using with comments. The sql for highlighting the actual link is at the bottom.
//connect to the database
mysql_connect("localhost", "root", "");
mysql_select_db("masscic");
//First grab the associated article id from the index page link and display the full article on this page
$id = $_GET['gid'];
//Now build the sql to grab the data in the generalinfo table in mysql
$sqlCommand = mysql_query("SELECT * FROM generalinfo WHERE gid='$id'");
//now loop through the data in the generalinfo table
while($row = mysql_fetch_array($sqlCommand)){
$id = $row['gid'];
$catid = $row['catid'];
$title = $row['title'];
$pic = $row['picURL'];
$picAlt = $row['picALT'];
$picTitle = $row['picTitle'];
$content = $row['article_body'];
$date = $row['reported_date'];
$formID = 'general_details.php?gid='.$id;//echo this variable created so that users can post comments to a particular article since the form is below
}
//build the sql to grab the data in the blogcomments table in mysql
$sqlComments = mysql_query("SELECT * FROM geninfocomments WHERE gid='$id' ORDER BY cgid ASC") or die(mysql_error());
$num_rows = mysql_num_rows($sqlComments); //Grab the total number of comments based on this article id
//loop through the data in the blogcomments table and grab all the comments with the same id.
$displayComments = "";
while($row = mysql_fetch_array($sqlComments)){
$name = $row['name'];
$email = $row['email'];
$cmtDate = $row['comments_date'];
$comment = $row['comments_body'];
//echo this on the html page to display all comments
$displayComments .= "<ul><li>Posted By: <span>$name</span></li><li>On: $cmtDate</li></ul><p>$comment</p>";
}
//initialize the variables for the form if users want to post a comment
$name ='';
$email ='';
$website ='';
$comments ='';
$errorMsg ='';
if (isset($_POST['submit'])) {
//grab the form data
$curnum = 0; //will itemize the number of errors we have
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$comments = $_POST['comments_body'];
//do some injection cleaning
$name = stripslashes($name);
$email = stripslashes($email);
$website = stripslashes($website);
$comments = stripslashes($comments);
$name = strip_tags($name);
$email = strip_tags($email);
$website = strip_tags($website);
$comments = strip_tags($comments);
//check for errors
if (!$name) {
$curnum ++;
$errorMsg .= '<span style="color:#ff0000">'.$curnum.'. Your name is required</span><br />';
}
if (!$email) {
$curnum ++;
$errorMsg .= '<span style="color:#ff0000">'.$curnum.'. Your email address is required<br />';
}
if (!$comments) {
$curnum ++;
$errorMsg .= '<span style="color:#ff0000">'.$curnum.'. You need to post a comment<br />';
}
$name = mysql_real_escape_string($name);
$email = mysql_real_escape_string($email);
$website = mysql_real_escape_string($website);
$comments = mysql_real_escape_string($comments);
//done with error checking now perform the insert
if (empty($errorMsg)) {
$sqlInsert = mysql_query("INSERT INTO geninfocomments(gid, name, email, website, comments_date, comments_body) VALUES('$id','$name','$email','$website', now(), '$comments')") or die (mysql_error());
}
}
//build the footer categories menu this is where I want to highlight a link
$sqlCatMenu = mysql_query("SELECT * FROM categories ORDER BY category ASC") or die (mysql_error());
$num_rows = mysql_num_rows($sqlCatMenu);
//now loop through all data
$listCats = '';//this declares a compound variable for posting content to the html page
while ($row = mysql_fetch_array($sqlCatMenu)){
$mcatid = $row['catid'];
$mcName = $row['category'];
$mcURL = $row['urlPath'];
$active = $_GET['gid'];
if(!$listCats == $active) {
$listCats .= '<li><a href="../'.$mcURL.'"title="'.$mcName.'" class="active">'.$mcName.'</a></li>';
}
else {
$listCats .= '<li><a href="../'.$mcURL.'"title="'.$mcName.'">'.$mcName.'</a></li>';
}
}
Thanks very much for your help.
Gerry