class help/ navigation
Posted: Thu Dec 17, 2009 12:36 pm
Hi,
I new here. I bought a php book called PHP and MySQL web development by Luck Welling, and I've been practicing with it for a couple weeks. I'm on the section with classes now to dynamically build webpages. I started getting off track and trying to set up a navigation menu that uses images... later when I learn how to build in javascript with php I want to add in rollovers.
I set it up to display 5 images through an array with a empty link. The problem I'm having is trying to figure out how to put in the url for the link dynamically through a array or something of that sort.
If you get a change check the code and let me know how I could put the url into the link which is already running through the while loop.
Later I would like to use the code mentioned in the book which checks to see if the url match and display a different selected image.
Let me know what you think:
I new here. I bought a php book called PHP and MySQL web development by Luck Welling, and I've been practicing with it for a couple weeks. I'm on the section with classes now to dynamically build webpages. I started getting off track and trying to set up a navigation menu that uses images... later when I learn how to build in javascript with php I want to add in rollovers.
I set it up to display 5 images through an array with a empty link. The problem I'm having is trying to figure out how to put in the url for the link dynamically through a array or something of that sort.
If you get a change check the code and let me know how I could put the url into the link which is already running through the while loop.
Later I would like to use the code mentioned in the book which checks to see if the url match and display a different selected image.
Let me know what you think:
Code: Select all
<?php
class buildpage {
// attributes
public $page_title = 'Some site';
public $content = '<p>Default Content</p>';
public $nav_images = array (
'Home' => 'reg_home.png',
'About' => 'reg_about.png',
'Calculator' => 'reg_calculator.png',
'Feedback' => 'reg_feedback.png',
'Contact' => 'reg_contact.png'
);
// operations
public function display() {
echo "<html>\n\n<head>\n\n";
$this -> display_title();
echo "\n\n</head>\n\n<body>\n\n";
$this -> display_header();
$this -> display_nav($this -> nav_images);
echo $this -> content;
$this -> display_footer();
echo "\n\n</body>\n\n</html>";
}
public function display_title() {
echo '<title>' .$this -> page_title. '</title>';
}
public function display_header() {
echo '<h2>Page Header</h2>';
}
public function display_nav($nav_images) {
while(list($img, $src) = each($nav_images)) {
echo '<a href="#"><img src="'.$src.'" alt="'.$img.'" border="0" /></a>';
}
}
public function display_footer() {
echo '<h2>Page Footer</h2>';
}
} # end class
?>