HIGHLIGHT MENU ITEM

Hi guys… I am a php newbie. I followed a php CMS tutorial on youtoube: http://www.youtube.com/watch?v=nuOUyFimtQE&feature=list_related&playnext=1&list=PL11D6E5B9CA126A57

I am using and css class to style the buttons, and trying to implement a for loop to highlight the current button

I created the cms but they don’t explain how to highlight the current page button. Below is the code. Just concentrate on the NAVIGATION area at the bottom of the code. Any help will be greatly appreciated!

Thanks in advance for your help!

[php]

<?php //session_start();

/* Created by Adam Khoury @ www.developphp.com */

require_once “scripts/connect_to_mysql.php”;

// DETERMINE which page ID to USE in our query below ********************************************
if (!isset($_GET[‘pid’])) {
$pageid = ‘1’;
} else {
//$pageid = ereg_replace("[^0-9]", “”, $_GET[‘pid’]); // deprecated function
$pageid = preg_replace(’#[^0-9]#i’, ‘’, $_GET[‘pid’]); // filter everything but numbers for security(new)
//preg_replace($pattern, $replacement, $string);//preg_replace() Function structure
}

// Query the body section for the proper page***********
$sqlCommand = “SELECT pagebody FROM pages WHERE id=’$pageid’ LIMIT 1”;
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
$body = $row[“pagebody”];
}
mysqli_free_result($query);

//********* Query the module data for display **************
$sqlCommand = “SELECT modulebody FROM modules WHERE showing=‘1’ AND name=‘footer’ LIMIT 1”;
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
$footer = $row[“modulebody”];
}
mysqli_free_result($query);

//Query the module data for display******
$sqlCommand = “SELECT modulebody FROM modules WHERE showing=‘1’ AND name=‘custom1’ LIMIT 1”;
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
$custom1 = $row[“modulebody”];
}
mysqli_free_result($query);

/************************
NAVIGATION****
*************************/

$sqlCommand = “SELECT id, linklabel FROM pages WHERE showing=‘1’ ORDER BY id ASC”;
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
$record_count = mysqli_num_rows($query);//****

$menuDisplay = ‘’;
while ($row = mysqli_fetch_array($query)) {
$pid = $row[“id”];
$linklabel = $row[“linklabel”];

//*Prepare to Show and Highlight buttons

HERE’S THE TRICKY PART FOR ME******
$per_page=‘1’;
for ($x=0; $x < $record_count; $x=$x+$perpage)
if($pid!=$x){
//$pid = mysql_real_escape_string($pid);

//$menuDisplay .= '<a href="index.php?pid=' . $pid . '">' . $linklabel . '</a><br />';//original link
$menuDisplay .= '<ul class="jj"> <a href="index.php?pid='.$pid. '">' . $linklabel.'' . '</a></li><br />';}
else $pid=$pid/$pid;
$menuDisplay .= '<li class="selectedlink"><a href="index.php?pid='.$pid. '">' . $linklabel.'' . '</a></li><br />';

}
mysqli_free_result($query);
mysqli_close($myConnection);
?>[/b]

My Website
$logo
<?php echo $custom1;?>
<?php echo $menuDisplay;?>
<?php echo $body;?>
<?php echo $footer;?> [ <?php echo $pageid;?> ]
go to ADMIN PANEL

[/php]

[php]
/************************
NAVIGATION****
*************************/

$sqlCommand = “SELECT id, linklabel FROM pages WHERE showing=‘1’ ORDER BY id ASC”;
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
$record_count = mysqli_num_rows($query);//****

$menuDisplay = ‘’;
while ($row = mysqli_fetch_array($query)) {
$pid = $row[“id”];
$linklabel = $row[“linklabel”];

//if statement checks to see if the page id from GET is the same as the page id you are doing the nave for
//change “selected” and “not_selected” to the names of your CSS classes
if ($pageid == $pid) {
$class = “selected”;
} else {
$class = "not_selected
}

//*Prepare to Show and Highlight buttons

//HERE’S THE TRICKY PART FOR ME******
$per_page=‘1’;
for ($x=0; $x < $record_count; $x=$x+$perpage)
if($pid!=$x){
//$pid = mysql_real_escape_string($pid);

//$menuDisplay .= '<a href="index.php?pid=' . $pid . '">' . $linklabel . '</a><br />';//original link
$menuDisplay .= '<ul class="jj"> <a href="index.php?pid='.$pid. '">' . $linklabel.'' . '</a></li><br />';}
else $pid=$pid/$pid;

//I have put the $class variable as this class, because I don’t know your code so I don’t know where you need it
$menuDisplay .= ‘

  • ’ . $linklabel.’’ . ‘

  • ’;

    }
    [/php]

    missed the ";
    [php]
    if ($pageid == $pid) {
    $class = “selected”;
    } else {
    $class = “not_selected”;
    }
    [/php]

    AWSOME!

    I can’t believe so easy it was… Sorry for my lack of knowledge, but I have to say this, Thank you very much mass. I thought I would have to wait a few days to get the answer!

    Muchas gracias, mass! :wink:

    no problem mate, happy to help.

    Sorry for misspelling your name Maas… I just got carried out of excitement. Thanks again…

    Sponsor our Newsletter | Privacy Policy | Terms of Service