Clinton Posted January 4, 2009 Share Posted January 4, 2009 I know very little about pagination. I was having problems with a different script earlier and tried another one. This script works up until the point you click on another link. The link is "http://localhost/project/search.php?page=2" but all it does is display a blank page, properly formatted. No information, no results, no nothing. How do I fix this? <?php session_start(); include 'connect/project.htm'; $smajor = $_POST['major']; ?> <html> <head> <title>Intranet - <?php echo $smajor ?> Workings</title> <link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" /> <link rel="stylesheet" href="singlec.css" type="text/css" /> <link rel="stylesheet" href="constant.css" type="text/css" /> </head> <body> <div id="tail"> <div class="main"> <div id="top"> <div id="logo"> <a href="index.php"><img src="images/logo.png" alt="" /></a> </div> <div class="right"> <div id="topmenuposition"> </div> <div id="topmenu"> <div class="module_s10"> <div> <div> <div> <ul class="menu-nav"> <li class="item60"><a href="index.php"><span><em>Home</em></span></a></li> <li class="item29"><a href="aboutus.php"><span><em>About Us</em></span></a></li> <li class="item54"><a href="resources.php"><span><em>Resources</em></span></a></li> <li class="item55"><a href="press.php"><span><em>Press/Media</em></span></a></li> <li class="item56"><a href="contact.php"><span><em>Contact Us</em></span></a></li></ul> </div> </div> </div> </div> </div> </div> </div> <div id="header"> <div class="bg-right"> <div class="bg-left"> <div class="space"><img src="images/banner.png" alt="" /></div> </div> </div> </div> <div id="breadcrumb"> <div class="module_breadcrumb"> <div> <div> <div> <span class="breadcrumbs pathway"> </span> </div> </div> </div> </div> </div> <div id="wrapper"> <div class="indent"> <div id="right"> <?php include 'mmenu.php'; ?> <?php include 'linmenu.php'; ?> </div> <div id="content"> <div class="content-tl"> <div class="content-tr"> <div class="width"> <div id="boxes"> <div id="box1"> <div class="module"> <div class="first"> <div class="sec min-height"> <div class="box-indent"> <div class="width"> <h3><span><?php echo $smajor ?> Workings:</span></h3> <table width="95%" border="0" cellspacing="0" cellpadding="1" class="boxtitle"> <?php $tbl_name="thelist"; //your table name // How many adjacent pages should be shown on each side? $adjacents = 3; /* First get total number of rows in data table. If you have a WHERE clause in your query, make sure you mirror it here. */ $query = "SELECT COUNT(*) as num FROM $tbl_name WHERE dmajorp = '$smajor' ORDER BY jposted"; $total_pages = mysql_fetch_array(mysql_query($query)); $total_pages = $total_pages[num]; /* Setup vars for query. */ $targetpage = "search.php"; //your file name (the name of this file) $limit = 4; //how many items to show per page $page = $_GET['page']; if($page) $start = ($page - 1) * $limit; //first item to display on this page else $start = 0; //if no page var is given, set start to 0 /* Get data. */ $sql = "SELECT * FROM $tbl_name WHERE dmajorp = '$smajor' ORDER BY jposted LIMIT $start, $limit"; $result = mysql_query($sql); /* Setup page vars for display. */ if ($page == 0) $page = 1; //if no page var is given, default to 1. $prev = $page - 1; //previous page is page - 1 $next = $page + 1; //next page is page + 1 $lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up. $lpm1 = $lastpage - 1; //last page minus 1 /* Now we apply our rules and draw the pagination object. We're actually saving the code to a variable in case we want to draw it more than once. */ $pagination = ""; if($lastpage > 1) { $pagination .= "<div class=\"pagination\">"; //previous button if ($page > 1) $pagination.= "<a href=\"$targetpage?page=$prev\">« previous </a>"; else $pagination.= "<span class=\"disabled\">« previous </span>"; //pages if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter </a>"; } } elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some { //close to beginning; only hide later pages if($page < 1 + ($adjacents * 2)) { for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter </a>"; } $pagination.= "..."; $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1 </a>"; $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage </a>"; } //in middle; hide some front and some back elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination.= "<a href=\"$targetpage?page=1\">1 </a>"; $pagination.= "<a href=\"$targetpage?page=2\">2 </a>"; $pagination.= "..."; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter </a>"; } $pagination.= "..."; $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1 </a>"; $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage </a>"; } //close to end; only hide early pages else { $pagination.= "<a href=\"$targetpage?page=1\">1 </a>"; $pagination.= "<a href=\"$targetpage?page=2\">2 </a>"; $pagination.= "..."; for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter </a>"; } } } //next button if ($page < $counter - 1) $pagination.= "<a href=\"$targetpage?page=$next\">next » </a>"; else $pagination.= "<span class=\"disabled\">next »</span>"; $pagination.= "</div>\n"; } ?> <?php while($row = mysql_fetch_array($result)) {extract($row); ?> <thead> <tr><td> <a href="showad.php?id=<?php echo $id; ?>"><?php echo $jtitle; ?></a> - $<?php echo $salary; ?> </td></tr> </thead> <tr><td> <?php if (strlen($poverview) > 240) { $poverview = substr($poverview, 0, 239) . '...'; } echo $poverview; ?></td></tr> <tr><td><b><font color="lightgreen">Experience Desired: </font></b><?php echo $wexperience; ?> <b><font color="lightgreen">Location:</font></b> <?php echo $city; ?>, <?php echo $state; ?> <?php echo $zipcode; ?></td></tr> <tr><td><h3> </h3></td></tr> <?php } ?> </table> <?=$pagination?> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> <div id="footer"> <div class="bg"> <div class="right-bg"> <div class="left-bg"> <div class="space"> © 2009 </div> </div> </div> </div> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
Clinton Posted January 4, 2009 Author Share Posted January 4, 2009 I think I figured it out. I think it has to do with $smajor = $_POST['major']; which is called at the very beginning. When you go to the second page there is nothing posted so it's not calling that. Perhaps setting this as a session variable? Quote Link to comment Share on other sites More sharing options...
Clinton Posted January 4, 2009 Author Share Posted January 4, 2009 I FIGURED IT OUT!!!!!!!!! YES! It was exactly what I thought it was. 5 hours later. LoL if (!$_POST['major'] == NULL) {unset($_SESSION['smajor']); $_SESSION['smajor'] = $_POST['major']; $smajor = $_POST['major']; } else $smajor = $_SESSION['smajor'] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.