PHP - Navigation With Images And Php
I have an interesting question here. Below is my html of my navigation menu however I'm setting up something in my database which has some good stuff in it and I"m trying to figure out how to implement it all so that the images, links, and everything will still work properly. This will probably take some thinking and I can't come up with a way to do this while still being able to have the images appear right.
Code: [Select] <div id="navigation"> <img id="navigation" src="images/navigation.jpg" alt="Navigation" /> <a href="applications.php"><img class="links" src="images/applications1.jpg" alt="Applications" onmouseover="this.src = 'images/applications2.jpg'" onmouseout="this.src = 'images/applications1.jpg'" /></a> <a href="#"><img class="links" src="images/rules1.jpg" alt="Rules" onmouseover="this.src = 'images/rules2.jpg'" onmouseout="this.src = 'images/rules1.jpg'" /></a> <a href="#"><img class="links" src="images/history1.jpg" alt="History" onmouseover="this.src = 'images/history2.jpg'" onmouseout="this.src = 'images/history1.jpg'" /></a> <a href="#"><img class="links" src="images/frontoffice1.jpg" alt="Front Office" onmouseover="this.src = 'images/frontoffice2.jpg'" onmouseout="this.src = 'images/frontoffice1.jpg'" /></a> <a href="#"><img class="links" src="images/forums1.jpg" alt="Forums" onmouseover="this.src = 'images/forums2.jpg'" onmouseout="this.src = 'images/forums1.jpg'" /></a> <a href="#"><img class="links" src="images/roster1.jpg" alt="Roster" onmouseover="this.src = 'images/roster2.jpg'" onmouseout="this.src = 'images/roster1.jpg'" /></a> <a href="#"><img class="links" src="images/halloffame1.jpg" alt="Hall of Fame" onmouseover="this.src = 'images/halloffame2.jpg'" onmouseout="this.src = 'images/halloffame1.jpg'" /></a> <a href="#"><img class="links" src="images/backstage1.jpg" alt="Backstage" onmouseover="this.src = 'images/backstage2.jpg'" onmouseout="this.src = 'images/backstage1.jpg'" /></a> </div> <!-- End of navigation div --> Database Table - Menus fields- id, menuname Database Table - Menu Items fields - id, menu_id, contentpage_id, itemname, itemurl, itemorder Similar TutorialsIs there a way I can do this? Hi, I am am looking to develop further the code below. This code allows me to display a left navigation bar with Main Links and then if you click a Main link, that link is listed first in the list and its' submenu appears below. For the majority of links in the navigation bar this is fine. But for about 2 of the Main links this basic navigation is not suitable. I need the navigation for 2 of the links to offer more depth. So, for example, if you click Accessories in: Shoes Trousers Shirts Accessories Looks like this if Accessories is clicked: Accessories Belts Cuff Links Wallets Shoes Trousers Shirts Looks like this if belts is clicked (Main link name changed and submenu changed): Accessories - Belts Brown leather Black Leather Multicolour Designs All casual All formal Shoes Trousers Shirts Looks like this is Brown Leather is clicked: Brown Leather Belts Armani Brown Leather Belt 32" Armani Brown Leather Belt 34" Hugo Boss Brown Leather Belt 32" Hugo Boss Brown Leather Belt 34" Shoes Trousers Shirts Currently the code does not allow for this depth in the navigation bar. Any ideas how it could be done? Do I need additional tables for each subcategory. How do I ensure the category clicked does not appear in the rest of the navigation bar, as in the code I have at the moment? Currently the code is: $res = mysql_query("SELECT * FROM categories"); while($row = mysql_fetch_array($res)) { $cats[$row['categoryid']] = $row['categoryname']; } if(isset($_GET['category'])) { $selcat = $_GET['category']; } if(isset($_GET['product'])) { $prod_info = mysql_fetch_array(mysql_query("SELECT * FROM products WHERE productid = ".$_GET['product'])); //Prod_Info now gets stored for use in the main display. $selcat = $prod_info['categoryid']; } if(isset($selcat)) { echo "<a href='categorylist.php?category=".$selcat."'>".$cats[$selcat]."</a>"; unset($cats[$selcat]); //Gets rid of it for later. $res = mysql_query("SELECT productid,name FROM products WHERE categoryid = ".$selcat); while($row = mysql_fetch_array($res)) { echo "<a href='product.php?product=".$row['productid']."'>".$row['name']."</a>"; } } foreach($cats AS $key => $cat) { echo "<a href='categoryview.php?category=".$key."'>".$cat."</a>"; } Thank you for looking at this post, Matt. I have this script from http://lampload.com/...,view.download/ (I am not using a database) I can upload images fine, I can view files, but I want to delete them. When I press the delete button, nothing happens
http://www.jayg.co.u...oad_gallery.php
<form>
<?php $dir = dirname(__FILENAME__)."/images/gallery" ; $files1 = scandir($dir); foreach($files1 as $file){ if(strlen($file) >=3){ $foil = strstr($file, 'jpg'); // As of PHP 5.3.0 $foil = $file; $pos = strpos($file, 'css'); if ($foil==true){ echo '<input type="checkbox" name="filenames[]" value="'.$foil.'" />'; echo "<img width='130' height='38' src='images/gallery/$file' /><br/>"; // for live host //echo "<img width='130' height='38' src='/ABOOK/SORTING/gallery-dynamic/images/gallery/ $file' /><br/>"; } } }?> <input type="submit" name="mysubmit2" value="Delete"> </form>
any ideas please?
thanks
Hello! hello I have been using an array for page navigation from for a while. I got help with it from phpfreaks. http://www.phpfreaks.com/forums/index.php?topic=298526.msg1413629#msg1413629 I would like to go into the database now (MySQL). I have been learning on my own. so forgive the child like way of describing things. I know the array give rules to the server to follow. as of know with flat file the link address looks like "index.php?p=about" I see on some site it looks like "index.php?about". I figure it has something to do with the database. Is there some rules that are in place that the index file does not have to set? Does anyone know a php tutorial that deals with just page navigation from the database? I know its more then just that, still have database tables. something like this php form tutorial http://myphpform.com/php-form-tutorial.php hope this is not a waste of your time ttb Hey, I hope you will understand what I am saying, because english isn't my main language -.-, Anyway, I need to create a folder navigation, what I mean is like you got folder on your comp : C:\navThing\ (and many sub folders and files) what I want to do is list all files from the current directory where the user is. if he is in C:\navThing\ show dir and files in C:\navThing\ only... if he is in C:\navThing\lol\ show dir and files in C:\navThing\lol only... but I don't know how to get the user position, for the moment I'm using $_GET, but well, I don't think it's really secure... ( xxx.php?path=lol/ ) if anybody can think of any other way, where the user can't modify it tell me, I thougth session would be good, but what if he use previous... anyway any suggestion? Hello: I wanted to see if someone can help me figure out how to include data from my included navigation file. Meaning: I have this file called myNav.php (the database table storing this is "myUpcomingEvents"): Code: [Select] function spLeftMenu() { $spLeftMenu = " <div id=\"sideEvents\"> echo \" $mySideBarData; \"; </div> "; return $spLeftMenu; } I am trying to pull it into the Index.php page like this (the database table storing this is "myHome"): Code: [Select] <?php include('include/myConn.php'); include('include/myNav.php'); $query=mysql_query("SELECT * FROM myHome,myUpcomingEvents") or die("Could not get data from db: ".mysql_error()); while($result=mysql_fetch_array($query)) { $myPageData=$result['myPageData']; $mySideBarPageData=$result['mySideBarPageData']; } ?> <!DOCTYPE HTML> <html> <head></head> <body> <div id="siteContainer"> <div id="leftColumn"> <?php echo spLeftMenu(); ?> </div> <div id="mainContent"> <?php echo $myPageData; ?> </div> </div> </body> </html> Can't get it to work. It just writes out: Code: [Select] echo " ; "; Anyone know how I can get this to work? Thanks. hello. i wonder if anyone could help me to solve this puzzle. im trying to create a dynamic navigation using a database but i keep getting stuck. i have 2 database: Navigation with : Quote id navPos pageID level parent url 1 top 1 1 0 page1.php 2 top 2 2 1 page2.php 3 top 3 3 2 page3.php 4 top 4 3 3 page4.php 5 top 5 3 4 page5.php 6 top 6 3 5 page6.php and Pages with: Quote id pageName 1 page1 2 page2 3 page3 4 page4 5 page5 6 page6 now, what i want to happen is on each page i have 3 functions. 1 calling the top nav, 1 calling the side nav and 1 calling the bottom nav. for this each function should have 3 levels. level 1 = main top level level 2 = child to main top level level 3 = child to level 2 so for example. 2 tabs each with 3 levels and 1 page on each level. TOP NAV Quote levels - TAB 1 - TAB 2 LEVEL1 - page1 - page4 LEVEL2 - page2 - page5 LEVEL3 - page3- page6 now for the code. I'LL STICK TO JUST THE TOP NAV FOR NOW. on the page that will display the navigation's i have: I WOULD LIKE THEM TO DROP DOWN BUT THIS CODE WILL NOT DO THAT. just lists for now Code: [Select] <div id="navWrapper"> <?PHP $navPosion = "top"; ?> <div id="LEVEL1" class="LEVEL1"> <ul><?PHP echo Navigation::NavL1($pageID, $navPosion); ?></ul> </div> <div id="LEVEL2" class="LEVEL2"> <ul><?PHP echo Navigation::NavL2($pageID, $navPosion); ?></ul> </div> <div id="LEVEL3" class="LEVEL3"> <ul><?PHP echo Navigation::NavL3($pageID, $navPosion); ?></ul> </div> </div> these is the functions im trying to put together. in the Navigation class i have. Code: [Select] class Navigation extends Pages{-----lots of other code here.... public static function navL1($pageID, $navPosion){ //FIND CURRENT PAGE ID $page = new Pages(); //calling just the Pages class. $CP = $page->find_by_pageID($pageID); $CPid = $CP->id; //GET ALL PAGES FROM THE DB $allP = $page->find_all(); foreach ($allP as $allPs){ $allPname = $allPs->pageName; //GET INFO FROMTHE NAVIGATION TABLE $nav2 = new Navigation(); //calling the navigation extension $Cnav = $nav2->find_all(); foreach ($Cnav as $Cnavs){ $Nid = $Cnavs->id; $Npos = $Cnavs->navPos; $Npid = $Cnavs->pageID; $Nlevel = $Cnavs->level; $Npnt = $Cnavs->parent; $Nurl = $Cnavs->url; $Nord = $Cnavs->order; if($Nlevel = '1'){ //FIND ACTIVE TAB if($CPid == $allPid){ $selected_tab='class="selected"'; }else{ $selected_tab=''; } echo '<li><a '.$selected_tab.' href="'.$allPname.'.php">'.$Nlevel.''.$allPname.'</a></li>'; }// if($Nlevel == $navLevel //} //end Navigation() }//end foreach ($allP as $allPs) } //end getNav($pageID) THEN THE SAME AGAIN FOR : public static function navL2($pageID, $navPosion){ and public static function navL3($pageID, $navPosion){ what this does is list all the pages for example navL1 give me Quote page1 page2 page3 page4 page5 page6 i want it to only list where level is 1 or 2 or 3 in each of the functions i have this but it does not seem to work. Code: [Select] if($Nlevel = "1"){ i tried this but i nothing return. Code: [Select] if($Nlevel == "1"){ if i echo this out in navL1 Code: [Select] echo "<br/>".$Nid = $Cnavs->id; echo "<br/>".$Npos = $Cnavs->navPos; echo "<br/>".$Npid = $Cnavs->pageID; echo "<br/>".$Nlevel = $Cnavs->level; echo "<br/>".$Npnt = $Cnavs->parent; echo "<br/>".$Nurl = $Cnavs->url; it gives me back the last page (page6) 6 time over which is not even level1. its level3 Quote 6 top 6 3 5 page6.php so its missing the rest of the pages in the loop and just out putting the last one. i realise that i need more if's in my function but maybe there is a better way ? for example i need an if($Npos == top) and in navL2 and navL3 i need to only show sub tabs under the correct parent. etc... for now i just want to get what i can working .. any thoughts ???? maybe i can roll all 3 functions into 1 amazing function ???? that would be nice. thanks ricky
Hello! Can someone please explain to me why I do not read navigation from mysql database data?
Database
Code: <style type="text/css"> .navbar .dropdown-toggle, .navbar .dropdown-menu a { cursor: pointer; } .navbar .dropdown-item.active, .navbar .dropdown-item:active { color: inherit; text-decoration: none; background-color: inherit; } .navbar .dropdown-item:focus, .navbar .dropdown-item:hover { color: #16181b; text-decoration: none; background-color: #f8f9fa; } @media (min-width: 767px) { .navbar .dropdown-toggle:not(.nav-link)::after { display: inline-block; width: 0; height: 0; margin-left: .5em; vertical-align: 0; border-bottom: .3em solid transparent; border-top: .3em solid transparent; border-left: .3em solid; } } </style> <script type="text/javascript"> $(document).ready(function () { $('.navbar .dropdown-item').on('click', function (e) { var $el = $(this).children('.dropdown-toggle'); var $parent = $el.offsetParent(".dropdown-menu"); $(this).parent("li").toggleClass('open'); if (!$parent.parent().hasClass('navbar-nav')) { if ($parent.hasClass('show')) { $parent.removeClass('show'); $el.next().removeClass('show'); $el.next().css({"top": -999, "left": -999}); } else { $parent.parent().find('.show').removeClass('show'); $parent.addClass('show'); $el.next().addClass('show'); $el.next().css({"top": $el[0].offsetTop, "left": $parent.outerWidth() - 4}); } e.preventDefault(); e.stopPropagation(); } }); $('.navbar .dropdown').on('hidden.bs.dropdown', function () { $(this).find('li.dropdown').removeClass('show open'); $(this).find('ul.dropdown-menu').removeClass('show open'); }); }); </script> <?php $servername = "localhost"; $username = "root"; $password = ""; $db = new PDO("mysql:host=$servername;dbname=dbname", $username, $password); function menu_builder1($db, $parent_id) { $sql = $db->prepare("SELECT * FROM menu WHERE status = 1 ORDER BY position ASC"); if($sql->execute()) { while ($row = $sql->fetch(PDO::FETCH_ASSOC)) { $array[$row['menu_sub_id']][] = $row; } main_menu1($array); } } function main_menu1($array, $parent_id = false) { if(!empty($array[$parent_id])) { foreach ($array[$parent_id] as $item) { if ($item['dropdown'] == false) { echo '<li class="nav-item active"><a class="nav-link" href="' . $item['href'] . '">' . $item['name'] . '</a></li>'; } elseif ($item['dropdown'] == true) { echo '<li class="nav-item dropdown"><a class="nav-link dropdown-toggle" id="dropdown2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' . $item['name'] . '</a>'; sub_menu1($array, $item['menu_id']); echo '</li>'; } } } } function sub_menu1($array = array(), $parent_id = false) { if(!empty($array[$parent_id])) { echo '<ul class="dropdown-menu" aria-labelledby="dropdown2">'; foreach ($array[$parent_id] as $item) { if ($item['dropdown'] == false) { echo '<li class="dropdown-item"><a href="' . $item['href'] . '">' . $item['name'] . '</a></li>'; } elseif ($item['dropdown'] == true) { echo '<li class="dropdown-item dropdown"><a class="dropdown-toggle" id="dropdown2-1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' . $item['name'] . '</a>'; sub_sub_menu1($array, $item['menu_id']); echo '</li>'; } } echo "</ul>"; } } function sub_sub_menu1($array = array(), $parent_id = false) { if(!empty($array[$parent_id])) { echo '<ul class="dropdown-menu" aria-labelledby="dropdown2-1">'; foreach ($array[$parent_id] as $item) { if ($item['dropdown'] == false) { echo '<li class="dropdown-item"><a href="' . $item['href'] . '">' . $item['name'] . '</a></li>'; } } echo "</ul>"; } } ?> <div class="navbar navbar-expand-md navbar-dark bg-dark mb-4" role="navigation"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarCollapse"> <ul class="navbar-nav mr-auto"> <?=menu_builder1($db, 0)?> </ul> </div> </div>
hello navigation - how can i get the id of an active tab i have a top nav which is pulling its tabs from a database how can i get the id of the active tab then pass it in a global to side navigation this is the top nav code Code: [Select] <?PHP require_once("../includes/initialize.php"); global $topNavs; global $pageName; ?> <div id="navWrapper"> <?PHP $topNav = navL1::find_all(); ?> <div id="ddtabs3" class="solidblockmenu"> <ul> <?PHP foreach($topNav as $topNavs): ?> <li><a <?PHP echo ($pageName == $topNavs->title ? 'class="selected"' : '')?> href="<?PHP echo $topNavs->title; ?>.php" id="<?PHP echo $topNavs->title; ?>"><?PHP echo $topNavs->title; echo $topNavs->id;?></a></li> <?PHP endforeach; ?> </ul> </div><!-- #ddtabs3--> </div><!-- #navWrapper--> this prints the id of 5 which is the last tab in my database. if i have tab 1 active how can i get my loop to get that id ? thanks rick I am relatively new to PHP, trying to learn more every day. I have been enjoying using Server Side Includes in my sidebars, footer etc with good results, much handier and more efficient! I would like to do the same for the header and main site navigation. However, the main problem that I am not sure how to deal with comes from having 'active' links (differently coloured menu tab for the page the user is on) in my menu. Here is a small menu example: Code: [Select] <div class="menu"> <ul> <li><a href="nav.php" class="active">Home</a></li> <li><a href="nav2.php">About</a></li> <li><a href="products1.php">Products</a></li> <li><a href="products2.php">Products 2</a></li> <li><a href="products3.php">Products 3</a></li> </ul> </div> When the user is on the Home page, the class is set to active - i.e. a different colour. If I do a simple server side include with my navigation this will of course be across all the pages. Can anyone please advise on what I need to do to make the menu work correctly across all the pages? (have different tabs selected for each respective page). Any help / insight is much appreciated. Hi, I'm building a dynamic site for a college project (a CMS) and have been using a Lynda tutorial. When the user clicks on a subject, the sub menu appears for the (a UL with a UL), so there is an 'accordian effect'. However, when I click on one of the page links in the sub menu, the content for that page appears, but the second UL containing the links to the pages dissapears. It only re-appears when I click back on the parent element (the subject link). I'd really appreciate some help. I've tried editing this code below but have had no joy: Code: [Select] function public_navigation($sel_subject, $sel_page, $public = true) { $output = "<ul class=\"subjects\">"; $subject_set = get_all_subjects($public); while ($subject = mysql_fetch_array($subject_set)) { $output .= "<li"; if ($subject["id"] == $sel_subject['id']) { $output .= " class=\"selected\""; } $output .= "><a href=\"index.php?subj=" . urlencode($subject["id"]) . "\">{$subject["menu_name"]}</a></li>"; if ($subject["id"] == $sel_subject['id']) { $page_set = get_pages_for_subject($subject["id"], $public); $output .= "<ul class=\"pages\">"; while ($page = mysql_fetch_array($page_set)) { $output .= "<li"; if ($page["id"] == $sel_page['id']) { $output .= " class=\"selected\""; } $output .= "><a href=\"index.php?page=" . urlencode($page["id"]) . "\">{$page["menu_name"]}</a></li>"; } $output .= "</ul>"; } } $output .= "</ul>"; return $output; } The code that precedes this is as follows: Code: [Select] function get_all_subjects($public = true) { global $connection; $query = "SELECT * FROM Subjects "; if ($public) { $query .= "WHERE visible = 1 "; } $query .= "ORDER BY position ASC"; $subject_set = mysql_query($query, $connection); confirm_query($subject_set); return $subject_set; } function get_pages_for_subject($subject_id, $public = true) { global $connection; $query = "SELECT * FROM pages "; $query .= "WHERE subject_id = {$subject_id} "; if ($public) { $query .= "AND visible = 1 "; } $query .= "ORDER BY position ASC"; $page_set = mysql_query($query, $connection); confirm_query($page_set); return $page_set; } function get_subject_by_id($subject_id) { global $connection; $query = "SELECT * "; $query .= "FROM Subjects "; $query .= "WHERE id=" . $subject_id ." "; $query .= "LIMIT 1"; $result_set = mysql_query($query, $connection); confirm_query($result_set); // REMEMBER: // if no rows are returned, fetch_array will return false if ($subject = mysql_fetch_array($result_set)) { return $subject; } else { return NULL; } } function get_page_by_id($page_id) { global $connection; $query = "SELECT * "; $query .= "FROM pages "; $query .= "WHERE id=" . $page_id ." "; $query .= "LIMIT 1"; $result_set = mysql_query($query, $connection); confirm_query($result_set); // REMEMBER: // if no rows are returned, fetch_array will return false if ($page = mysql_fetch_array($result_set)) { return $page; } else { return NULL; } } function get_default_page($subject_id) { // Get all visible pages $page_set = get_pages_for_subject($subject_id, true); if ($first_page = mysql_fetch_array($page_set)) { return $first_page; } else { return NULL; } } function find_selected_page() { global $sel_subject; global $sel_page; if (isset($_GET['subj'])) { $sel_subject = get_subject_by_id($_GET['subj']); $sel_page = get_default_page($sel_subject['id']); } elseif (isset($_GET['page'])) { $sel_subject = NULL; $sel_page = get_page_by_id($_GET['page']); } else { $sel_subject = NULL; $sel_page = NULL; } } function navigation($sel_subject, $sel_page, $public = false) { $output = "<ul class=\"subjects\">"; $subject_set = get_all_subjects($public); while ($subject = mysql_fetch_array($subject_set)) { $output .= "<li"; if ($subject["id"] == $sel_subject['id']) { $output .= " class=\"selected\""; } $output .= "><a href=\"edit_subject.php?subj=" . urlencode($subject["id"]) . "\">{$subject["menu_name"]}</a></li>"; $page_set = get_pages_for_subject($subject["id"], $public); $output .= "<ul class=\"pages\">"; while ($page = mysql_fetch_array($page_set)) { $output .= "<li"; if ($page["id"] == $sel_page['id']) { $output .= " class=\"selected\""; } $output .= "><a href=\"content.php?page=" . urlencode($page["id"]) . "\">{$page["menu_name"]}</a></li>"; } $output .= "</ul>"; } $output .= "</ul>"; return $output; } Hi PHP Freaks! Here is my problem. I want to have a PHP navigation system that uses Arrays to control it. Code: [Select] $nav = array( "title1" => "url1", "title2" => array( "sub-page1" => "url1", "sub-page2" => "url2" ), "title3" => array( "sub-page1" => "url1", "sub-page2" => "url2" ), "title4" => array( "sub-page1" => "url1", "sub-page2" => "url2" ), "title5" => "url1", "title6" => "url1" ); $loc = basename($_SERVER["REQUEST_URI"]); What I'm trying to do, is if the $loc is a url in "title4" I want a ul/li printout of that array. Any help you could share with me would be MUCH appreciated. The printout should look like: Code: [Select] <ul> <li>Title4<ul> <li>url1</li> <li>url2</li> </ul></li> </ul> I was talking to some friends, who are just as new as me in programming, and they think it would be better to use a single navigation file for every link in a web site. Something like this: Code: [Select] <a href="nav.php?id=home&otherparams" >Home</a> <a href="nav.php?id=products&otherparams" >Products</a> <a href="nav.php?id=contact&otherparams" >Contact</a> I told them I think this might be easier to maintain, but also might take up on loading time, as the site viewer will have to go through an extra node to get where he wants. Is this single navigation file a good practice or should it be avoided? Thanks for any comments... im trying to write a simple script. Pretty much to scrape a page content. maybe you can help me. This is what i got so far <?php $url = 'http://www.solecollector.com/forums/memberlist.php'; $output = file_get_contents($url); echo $output; ?> which works good. Now how could i have it navigate to the next page and run the script again, and do so untill it reaches the last page. Any help its appreciated or point me on the right direction. Hi guys, I recently wrote a pagination script and it works fine, except from when trying to echo the navigation. This is the Pagination.php Script Code: [Select] <?php class Pagination { /** * Current Page * * @var integer */ var $page; /** * Size of the records per page * * @var integer */ var $size; /** * Total records * * @var integer */ var $total_records; /** * Link used to build navigation * * @var string */ var $link; /** * Class Constructor * * @param integer $page * @param integer $size * @param integer $total_records */ function Pagination($page = null, $size = null, $total_records = null) { $this->page = $page; $this->size = $size; $this->total_records = $total_records; } /** * Set's the current page * * @param unknown_type $page */ function setPage($page) { $this->page = 0+$page; } /** * Set's the records per page * * @param integer $size */ function setSize($size) { $this->size = 0+$size; } /** * Set's total records * * @param integer $total */ function setTotalRecords($total) { $this->total_records = 0+$total; } /** * Sets the link url for navigation pages * * @param string $url */ function setLink($url) { $this->link = $url; } /** * Returns the LIMIT sql statement * * @return string */ function getLimitSql() { $sql = " WHERE school = 'ssb' ORDER BY orientation LIMIT " . $this->getLimit(); return $sql; } /** * Get the LIMIT statment * * @return string */ function getLimit() { if ($this->total_records == 0) { $lastpage = 0; } else { $lastpage = ceil($this->total_records/$this->size); } $page = $this->page; if ($this->page < 1) { $page = 1; } else if ($this->page > $lastpage && $lastpage > 0) { $page = $lastpage; } else { $page = $this->page; } $sql = ($page - 1) * $this->size . "," . $this->size; return $sql; } /** * Creates page navigation links * * @return string */ function create_links() { $totalItems = $this->total_records; $perPage = $this->size; $currentPage = $this->page; $link = $this->link; $totalPages = floor($totalItems / $perPage); $totalPages += ($totalItems % $perPage != 0) ? 1 : 0; if ($totalPages < 1 || $totalPages == 1){ return null; } $output = null; //$output = '<span id="total_page">Page (' . $currentPage . '/' . $totalPages . ')</span> '; $loopStart = 1; $loopEnd = $totalPages; if ($totalPages > 5) { if ($currentPage <= 3) { $loopStart = 1; $loopEnd = 5; } else if ($currentPage >= $totalPages - 2) { $loopStart = $totalPages - 4; $loopEnd = $totalPages; } else { $loopStart = $currentPage - 2; $loopEnd = $currentPage + 2; } } if ($loopStart != 1){ $output .= sprintf('<li class="disabledpage"><a href="' . $link . '">&#171;</a></li>', '1'); } if ($currentPage > 1){ $output .= sprintf('<li class="nextpage"><a href="' . $link . '">Previous</a></li>', $currentPage - 1); } for ($i = $loopStart; $i <= $loopEnd; $i++) { if ($i == $currentPage){ $output .= '<li class="currentpage">' . $i . '</li> '; } else { $output .= sprintf('<li><a href="' . $link . '">', $i) . $i . '</a></li> '; } } if ($currentPage < $totalPages){ $output .= sprintf('<li class="nextpage"><a href="' . $link . '">Next</a></li>', $currentPage + 1); } if ($loopEnd != $totalPages){ $output .= sprintf('<li class="nextpage"><a href="' . $link . '">&#187;</a></li>', $totalPages); } return "<div class='pagination'><ul>" . $output . "</ul></div>"; } } ?> And this is the actual page which needs paginating: Code: [Select] <?php include('Pagination.php'); $page = 1; // how many records per page $size = 9; // we get the current page from $_GET if (isset($_GET['page'])){ $page = (int) $_GET['page']; } // create the pagination class $pagination = new Pagination(); $pagination->setLink("album.php?page=%s"); $pagination->setPage($page); $pagination->setSize($size); $pagination->setTotalRecords($total_records); // now use this SQL statement to get records from your table //$SQL = "SELECT * FROM mytable " . $pagination->getLimitSql(); $myServer = "********"; $myUser = "*******"; $myPass = "*******"; $myDB = "*******"; //connection to the database $dbhandle = mysql_connect($myServer, $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer"); //select a database to work with $selected = mysql_select_db($myDB, $dbhandle) or die("Couldn't open database $myDB"); $album_query = "SELECT * FROM albums WHERE album_name = '" . $_REQUEST['album'] . "' "; $album_result = mysql_query($album_query) or die('Error Getting Information Requested for album'); $album_row = mysql_fetch_array($album_result); $album = $_REQUEST['album'] . " " . $album_row['school']; $photo_query = "SELECT * FROM `" . $album . "` " . $pagination->getLimitSql(); //$photo_query = "SELECT * FROM `" . $album . "` WHERE school = 'ssb' ORDER BY orientation" . $pagination->getLimitSql(); $photo_result = mysql_query($photo_query) or die('Error Getting Information Requested for photos'); $photo_row = mysql_fetch_array($photo_result); $photo_row_count = mysql_num_rows($photo_result); $i = 0; $cellcnt = 0; while ($i < $photo_row_count) { $thumb_selection = $_REQUEST['album'] . " " . $album_row['school']; $photo_selection = $_REQUEST['album'] . " " . $album_row['school']; if($thumb_selection == "nutcracker 2007 ssb") $act_thumb = mysql_result($photo_result,$i,"thumbnail"); else $act_thumb = mysql_result($photo_result,$i,"thumbnail") . "/" . mysql_result($photo_result,$i,"photo_id") . ".jpg"; if($photo_selection == "nutcracker 2007 ssb") $act_photo = mysql_result($photo_result,$i,"photo_path"); else $act_photo = mysql_result($photo_result,$i,"photo_path") . "/" . mysql_result($photo_result,$i,"photo_id") . ".jpg"; if (!(mysql_result($photo_result,$i,"photo_name") == "")) $photo_name_font_tag = "<font style=' padding: 5px; background-color:grey; font-family: Vag Round, Vag Rounded; color: #C02777;'>"; else $photo_name_font_tag = "<font style='font-family: Vag Round, Vag Rounded; color: #C02777;'>"; $f1 =" <td align='center'> <a class='grouped_elements' rel='group1' href='" . $act_photo . "'><img src='" . $act_thumb . "' /> <br /> " . mysql_result($photo_result,$i,"photo_name") . "</a> </td></font> "; echo "" . $f1 .""; $cellcnt++; if ($cellcnt == 3) { echo "</tr> <tr>"; $cellcnt = 0; } $i++; } ?> </table> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> <?php $navigav = $pagination->create_links(); //$navigav = $pagination -> create_links($output); echo $navigav; ?> Any help would be greatly appreciated! Jacob. Hi guys! I need a php page that is splitted into 2 screens. One will display the navigation menu and the second one is the iframe. As for the navigation menu, I am getting the list of all files in the current directory with readdir(). Then I create an array with all of the items that are folders (is_dir() function) and apply the same script on them. My problem is to correctly display all of the information I gather in an adequate manner. Can anyone help me with that? Also if anyone has ready-to-go scripts, I would highly appreciate that too. Also, once a user choose a file, it should be loaded in the iframe. How do I specify "src" attribute for the iframe, in that case? Thanks! Selected navigation on include file. Hi all I can't think how to do this or even if it's possible so I'm hoping someone can help. I have a simple example here to illustrate. http://www.ttmt.org.uk/three.php It's just four linked pages with a heading and a navigation. The navigation has an id="selected" in the <a> tag for that page that changes the color of that link to show you are on that page - very basic. I wanted the put the navigation on the pages with an include file. Code: [Select] <?php include("php/includes/nav.php"); ?> and have the code for the nav in nav.php nav.php Code: [Select] <ul id="nav"> <li><a href="index.php">Home</a></li> <li><a href="one.php">One</a></li> <li><a href="two.php">Two</a></li> <li><a href="three.php">Three</a></li> </ul> My problem is how can I add the id="selected" to the different links for the different pages if I'm including the navigation code? Hope this makes sense and someone can help. Any help would be greatly appreciated. Code: [Select] <div id="nav"> <ul> <li class="item"><a href="/">Home</a>/</li> <li class="item"><a href="/one">one</a></li> <li class="item"><a href="/two>two</a></li> <li class="item"><a href="/three">three</a></li> </ul> <div> i want to add class='active' to the a tags . when the menu is the current page. namely.when i on the home page. the a label is Code: [Select] <li class="item"><a href="/" class="active">Home</a>/</li> .but the others a label are not have class="active". when i on the one page. it is is Code: [Select] <li class="item"><a href="one" class="active">one</a>/</li>.the others a label are not have class="active". |