PHP - Page Navigation With Php
Similar Tutorialshello 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 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=327715.0 Hi, I have a very long page filled with content, suppose i want to navigate to the bottom of the page, its difficult for user to scroll down the page. for example: i have kept all in one long page about us Services when i click the services page i want to go the services content, how to do this. About us about us content blahblahblahblahblahblahblahblahblahblahblahblahb lahblahblahblahblahblahblahblahblahblahblahblahbl ahblahblahblahblahblahblahblahblahblah Services Services content blahblahblahblahblahblahblahblahblahblahblahblahb lahblahblahblahblahblahblahblahblahblahblahblahbl ahblahblahblahblahblahblahblahblahblah Thanks, 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. Quesion: Show each movie in the database on its own page, and give the user links in a "page 1, Page 2, Page 3" - type navigation system. Hint: Use LIMIT to control which movie is on which page. I have provided 3 files: 1st: configure DB, 2nd: insert data, 3rd: my code for the question. I would appreciate the help. I am a noob by the way. First set up everything for DB: <?php //connect to MySQL $db = mysql_connect('localhost', 'root', '000') or die ('Unable to connect. Check your connection parameters.'); //create the main database if it doesn't already exist $query = 'CREATE DATABASE IF NOT EXISTS moviesite'; mysql_query($query, $db) or die(mysql_error($db)); //make sure our recently created database is the active one mysql_select_db('moviesite', $db) or die(mysql_error($db)); //create the movie table $query = 'CREATE TABLE movie ( movie_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, movie_name VARCHAR(255) NOT NULL, movie_type TINYINT NOT NULL DEFAULT 0, movie_year SMALLINT UNSIGNED NOT NULL DEFAULT 0, movie_leadactor INTEGER UNSIGNED NOT NULL DEFAULT 0, movie_director INTEGER UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (movie_id), KEY movie_type (movie_type, movie_year) ) ENGINE=MyISAM'; mysql_query($query, $db) or die (mysql_error($db)); //create the movietype table $query = 'CREATE TABLE movietype ( movietype_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT, movietype_label VARCHAR(100) NOT NULL, PRIMARY KEY (movietype_id) ) ENGINE=MyISAM'; mysql_query($query, $db) or die(mysql_error($db)); //create the people table $query = 'CREATE TABLE people ( people_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, people_fullname VARCHAR(255) NOT NULL, people_isactor TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, people_isdirector TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (people_id) ) ENGINE=MyISAM'; mysql_query($query, $db) or die(mysql_error($db)); echo 'Movie database successfully created!'; ?> ******************************************************************** *********************************************************************** second file to load info into DB: <?php // connect to MySQL $db = mysql_connect('localhost', 'root', '000') or die ('Unable to connect. Check your connection parameters.'); //make sure you're using the correct database mysql_select_db('moviesite', $db) or die(mysql_error($db)); // insert data into the movie table $query = 'INSERT INTO movie (movie_id, movie_name, movie_type, movie_year, movie_leadactor, movie_director) VALUES (1, "Bruce Almighty", 5, 2003, 1, 2), (2, "Office Space", 5, 1999, 5, 6), (3, "Grand Canyon", 2, 1991, 4, 3)'; mysql_query($query, $db) or die(mysql_error($db)); // insert data into the movietype table $query = 'INSERT INTO movietype (movietype_id, movietype_label) VALUES (1,"Sci Fi"), (2, "Drama"), (3, "Adventure"), (4, "War"), (5, "Comedy"), (6, "Horror"), (7, "Action"), (8, "Kids")'; mysql_query($query, $db) or die(mysql_error($db)); // insert data into the people table $query = 'INSERT INTO people (people_id, people_fullname, people_isactor, people_isdirector) VALUES (1, "Jim Carrey", 1, 0), (2, "Tom Shadyac", 0, 1), (3, "Lawrence Kasdan", 0, 1), (4, "Kevin Kline", 1, 0), (5, "Ron Livingston", 1, 0), (6, "Mike Judge", 0, 1)'; mysql_query($query, $db) or die(mysql_error($db)); echo 'Data inserted successfully!'; ?> ************************************************************** **************************************************************** MY CODE FOR THE QUESTION: <?php $db = mysql_connect('localhost', 'root', '000') or die ('Unable to connect. Check your connection parameters.'); mysql_select_db('moviesite', $db) or die(mysql_error($db)); //get our starting point for the query from the URL if (isset($_GET['offset'])) { $offset = $_GET['offset']; } else { $offset = 0; } //get the movie $query = 'SELECT movie_name, movie_year FROM movie ORDER BY movie_name LIMIT ' . $offset . ' , 1'; $result = mysql_query($query, $db) or die(mysql_error($db)); $row = mysql_fetch_assoc($result); ?> <html> <head> <title><?php echo $row['movie_name']; ?></title> </head> <body> <table border = "1"> <tr> <th>Movie Name</th> <th>Year</th> </tr><tr> <td><?php echo $row['movie_name']; ?></td> <td><?php echo $row['movie_year']; ?></td> </tr> </table> <p> <a href="page.php?offset=0">Page 1</a>, <a href="page.php?offset=1">Page 2</a>, <a href="page.php?offset=2">Page 3</a> </p> </body> </html> Hello! 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 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. 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 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>
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? Some code from my pages ,
Page1 ( Redirecting page )
<html> <title>login_redirect.</title> body> <form name="redirect" action="http://mysite/page2.php" method="post"> <input type="hidden" name="mac" value="$(mac)"> </form> <script language="JavaScript"> <!-- document.redirect.submit(); //--> </script> </body> </html>Page 2 ( select product ) <?php session_start(); ini_set('display_errors',1); error_reporting(E_ALL); include '../lib/config.php'; include '../lib/opendb.php'; // get user mac adres from redirect post page1 $_SESSION['macid'] = $_POST['mac']; // set $macid for other use ( maybe not needed, am learning ) $macid = $_SESSION['macid']; // echo $macid does show mac adress, so variable is not empty here if (!empty($_POST["submit"])) { $product_choice = $_POST['accounttype']; $query= "SELECT AccountIndex, AccountCost, AccountName FROM AccountTypes WHERE AccountIndex='$product_choice'"; $result = mysql_query($query) or die('Query failed. ' . mysql_error()); while($row = mysql_fetch_array($result)) { $_SESSION['AccountIndex'] = $row['AccountIndex']; $_SESSION['AccountCost'] = $row['AccountCost']; $_SESSION['AccountName'] = $row['AccountName']; } header('Location: page3.php'); } // did leave out the other/html/form stuff herePage 3 ( show Session variables ) <?php ini_set('display_errors',1); error_reporting(E_ALL); session_start(); print_r($_SESSION); ?>Now, on page 3 i do see the right session varables, only the "macid" is empty. why ? 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! 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. 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. 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... 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; } Is there a way I can do this? |