Search the Community
Showing results for tags 'pagination'.
-
I have a blog with the blog entries in a directory (very unsecure, I know) and on my home page I have a foreach(); function that retrieves all of the files (blog entries) from the entries directory. I've posted so many entries, my homepage is taking a very long time to load. Is there any way to paginate this foreach(); function? Here is my code foreach (glob("entries/*.php") as $filename) { include $filename; }
-
We Have online shopping portal Named Oshopindia.com recently we created mobile website for oshopindia on products page we want to add pagination for products We impliment many code of pagination but it's not working properly in mobile website Can anybody Suggest me any simple pagination code for Mobile website
-
Hi Professionals I have wrote a webpage and my pagination is not working correctly when I click the next page, I am pretty new to php so I am a bit lost hoping one of yous can help, here is my full page attached which probably is a mess to yous fashionindex.php style.css
-
Hi folks, you could help me with a PHP question. I changed our pagination from .../?page=0%2C0%2C1 to ?page=1. The problem now is that a few custom codes aren't working anymore. There is one code that puts all following pages as nofollow/noindex. The code worked with the long pagination URL but not with the short. Here's the code: <?php $target_page= explode("/",$_SERVER['REQUEST_URI']); $target_page= $target_page[1]; $pages_with_nofollow = array( 'nyc-apartments-by-school', 'park', ); if(in_array($target_page, $pages_with_nofollow) ===true){ $target_page_num = isset($_GET['page']) ? explode(",",$_GET['page']) : 0; $target_page_num = !empty($target_page_num) ? $target_page_num[2] : 0; if($target_page_num > 0){ $variables['head'] .= '<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">'; } } ?> What do I need to change? Thank you!!!
-
I have a search class with pagination and I can get the first page to display correctly but the next page gives a bunch of undefined index(s). I know i need to pass the variables to the next page but it only uses one "View" and a "Class". I have tried to make all the $_POST variables into $_SESSIONS and that still did not work. Im sure if I could make the pagination stay at "Search" and not go to "Search?page=2" it might work, but I don't know how to do that exactly. Here is the Pagination and Search Function class/code: <?php class Search extends MainController{ function __construct(){ parent::__construct(); $this->view->url = $this->config->url; $this->view->ID = get_class($this); $this->view->Title = "Diablo 3 Online Auction House"; $this->view->msg = ""; $this->view->err = false; $itemName = isset($_POST['item_name']) ? $_POST['item_name'] : ''; $val_1 = $_POST['attrib1']; $val_2 = $_POST['attrib2']; $val_3 = $_POST['attrib3']; $val_4 = $_POST['attrib4']; $val_5 = $_POST['attrib5']; $val_6 = $_POST['attrib6']; $val_7 = $_POST['attrib7']; $val_8 = $_POST['attrib8']; $itemAttrib1 = $_POST['list_1']; $itemAttrib2 = $_POST['list_2']; $itemAttrib3 = $_POST['list_3']; $itemAttrib4 = $_POST['list_4']; $itemAttrib5 = $_POST['list_5']; $itemAttrib6 = $_POST['list_6']; $itemAttrib7 = $_POST['list_7']; $itemAttrib8 = $_POST['list_8']; $Quality = $_POST['quality']; $Type = $_POST['type']; $sub_Type = $_POST['sub']; $page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1; // If the page wasn't set, lets set $page to number 1 for the first page $sql = "SELECT * FROM items_us_sc WHERE item_name = :item_name AND quality = :quality AND type = :type AND sub_type = :sub AND ((attrib_1 = :prop1 AND value_1 >= :val1 OR attrib_2 = :prop1 AND value_2 >= :val1 OR attrib_3 = :prop1 AND value_3 >= :val1 OR attrib_4 = :prop1 AND value_4 >= :val1 OR attrib_5 = :prop1 AND value_5 >= :val1 OR attrib_6 = :prop1 AND value_6 >= :val1 OR attrib_7 = :prop1 AND value_7 >= :val1 OR attrib_8 = :prop1 AND value_8 >= :val1) AND (attrib_1 = :prop2 AND value_1 >= :val2 OR attrib_2 = :prop2 AND value_2 >= :val2 OR attrib_3 = :prop2 AND value_3 >= :val2 OR attrib_4 = :prop2 AND value_4 >= :val2 OR attrib_5 = :prop2 AND value_5 >= :val2 OR attrib_6 = :prop2 AND value_6 >= :val2 OR attrib_7 = :prop2 AND value_7 >= :val2 OR attrib_8 = :prop2 AND value_8 >= :val2) AND (attrib_1 = :prop3 AND value_1 >= :val3 OR attrib_2 = :prop3 AND value_2 >= :val3 OR attrib_3 = :prop3 AND value_3 >= :val3 OR attrib_4 = :prop3 AND value_4 >= :val3 OR attrib_5 = :prop3 AND value_5 >= :val3 OR attrib_6 = :prop3 AND value_6 >= :val3 OR attrib_7 = :prop3 AND value_7 >= :val3 OR attrib_8 = :prop3 AND value_8 >= :val3) AND (attrib_1 = :prop4 AND value_1 >= :val4 OR attrib_2 = :prop4 AND value_2 >= :val4 OR attrib_3 = :prop4 AND value_3 >= :val4 OR attrib_4 = :prop4 AND value_4 >= :val4 OR attrib_5 = :prop4 AND value_5 >= :val4 OR attrib_6 = :prop4 AND value_6 >= :val4 OR attrib_7 = :prop4 AND value_7 >= :val4 OR attrib_8 = :prop4 AND value_8 >= :val4) AND (attrib_1 = :prop5 AND value_1 >= :val5 OR attrib_2 = :prop5 AND value_2 >= :val5 OR attrib_3 = :prop5 AND value_3 >= :val5 OR attrib_4 = :prop5 AND value_4 >= :val5 OR attrib_5 = :prop5 AND value_5 >= :val5 OR attrib_6 = :prop5 AND value_6 >= :val5 OR attrib_7 = :prop5 AND value_7 >= :val5 OR attrib_8 = :prop5 AND value_8 >= :val5) AND (attrib_1 = :prop6 AND value_1 >= :val6 OR attrib_2 = :prop6 AND value_2 >= :val6 OR attrib_3 = :prop6 AND value_3 >= :val6 OR attrib_4 = :prop6 AND value_4 >= :val6 OR attrib_5 = :prop6 AND value_5 >= :val6 OR attrib_6 = :prop6 AND value_6 >= :val6 OR attrib_7 = :prop6 AND value_7 >= :val6 OR attrib_8 = :prop6 AND value_8 >= :val6) AND (attrib_1 = :prop7 AND value_1 >= :val7 OR attrib_2 = :prop7 AND value_2 >= :val7 OR attrib_3 = :prop7 AND value_3 >= :val7 OR attrib_4 = :prop7 AND value_4 >= :val7 OR attrib_5 = :prop7 AND value_5 >= :val7 OR attrib_6 = :prop7 AND value_6 >= :val7 OR attrib_7 = :prop7 AND value_7 >= :val7 OR attrib_8 = :prop7 AND value_8 >= :val7) AND (attrib_1 = :prop8 AND value_1 >= :val8 OR attrib_2 = :prop8 AND value_2 >= :val8 OR attrib_3 = :prop8 AND value_3 >= :val8 OR attrib_4 = :prop8 AND value_4 >= :val8 OR attrib_5 = :prop8 AND value_5 >= :val8 OR attrib_6 = :prop8 AND value_6 >= :val8 OR attrib_7 = :prop8 AND value_7 >= :val8 OR attrib_8 = :prop8 AND value_8 >= :val8))"; $arr = array(":item_name" => $itemName, ":quality" => $Quality, ":type" => $Type, ":sub" => $sub_Type, ":prop1" => $itemAttrib1, ":val1" => $val_1, ":val2" => $val_2, ":val3" => $val_3, ":val4" => $val_4, ":val5" => $val_5, ":val6" => $val_6, ":val7" => $val_7, ":val8" => $val_8, ":prop2" => $itemAttrib2, ":prop3" => $itemAttrib3, ":prop4" => $itemAttrib4, ":prop5" => $itemAttrib5, ":prop6" => $itemAttrib6, ":prop7" => $itemAttrib7, ":prop8" => $itemAttrib8); $ctr = $this->database->DBCtr($sql,$arr); $this->view->count = $ctr; // Lets set how many messages we want to display $per_page = "5"; // Now we must calculate the last page $last_page = ceil($ctr/$per_page); // And set the first page $first_page = "1"; // Here we are making the "First page" link if ($page == $first_page){ $this->view->first = "<li class='disabled'><a href='?page=".$first_page."'>First page</a></li>"; }else{ $this->view->first = "<li><a href='?page=".$first_page."'>First page</a></li>"; } // If page is 1 then remove link from "Previous" word if($page == $first_page){ $this->view->prev = "<li class='disabled'><a>Previous</a></li>"; }else{ if(!isset($page)){ $this->view->prev = "<li><a>Previous</a></li>"; }else{ // But if page is set and it's not 1.. Lets add link to previous word to take us back by one page $previous = $page-1; $this->view->prev = "<li><a href='?page=".$previous."'>Previous</a></li>"; } } // If the page is last page.. lets remove "Next" link if($page == $last_page){ $this->view->next = "<li class='disabled'><a>Next</a></li>"; }else{ // If page is not set or it is set and it's not the last page.. lets add link to this word so we can go to the next page if(!isset($page)){ $next = $first_page+1; $this->view->next = "<li><a href='?page=".$next."'>Next</a></li> "; }else{ $next = $page+1; $this->view->next = "<li><a href='?page=".$next."'>Next</a></li>"; } } // And now lets add the "Last page" link if ($page == $last_page){ $this->view->last = "<li class='disabled'><a href='?page=".$last_page."'>Last page</a></li>"; }else{ $this->view->last = "<li><a href='?page=".$last_page."'>Last page</a></li>"; } // Math.. It gets us the start number of message that will be displayed $start = (($page * $per_page) - $per_page); // Now lets set the limit for our query $limit = "LIMIT $start, $per_page"; $sql = "SELECT * FROM items_us_sc WHERE item_name = :item_name AND quality = :quality AND type = :type AND sub_type = :sub AND ((attrib_1 = :prop1 AND value_1 >= :val1 OR attrib_2 = :prop1 AND value_2 >= :val1 OR attrib_3 = :prop1 AND value_3 >= :val1 OR attrib_4 = :prop1 AND value_4 >= :val1 OR attrib_5 = :prop1 AND value_5 >= :val1 OR attrib_6 = :prop1 AND value_6 >= :val1 OR attrib_7 = :prop1 AND value_7 >= :val1 OR attrib_8 = :prop1 AND value_8 >= :val1) AND (attrib_1 = :prop2 AND value_1 >= :val2 OR attrib_2 = :prop2 AND value_2 >= :val2 OR attrib_3 = :prop2 AND value_3 >= :val2 OR attrib_4 = :prop2 AND value_4 >= :val2 OR attrib_5 = :prop2 AND value_5 >= :val2 OR attrib_6 = :prop2 AND value_6 >= :val2 OR attrib_7 = :prop2 AND value_7 >= :val2 OR attrib_8 = :prop2 AND value_8 >= :val2) AND (attrib_1 = :prop3 AND value_1 >= :val3 OR attrib_2 = :prop3 AND value_2 >= :val3 OR attrib_3 = :prop3 AND value_3 >= :val3 OR attrib_4 = :prop3 AND value_4 >= :val3 OR attrib_5 = :prop3 AND value_5 >= :val3 OR attrib_6 = :prop3 AND value_6 >= :val3 OR attrib_7 = :prop3 AND value_7 >= :val3 OR attrib_8 = :prop3 AND value_8 >= :val3) AND (attrib_1 = :prop4 AND value_1 >= :val4 OR attrib_2 = :prop4 AND value_2 >= :val4 OR attrib_3 = :prop4 AND value_3 >= :val4 OR attrib_4 = :prop4 AND value_4 >= :val4 OR attrib_5 = :prop4 AND value_5 >= :val4 OR attrib_6 = :prop4 AND value_6 >= :val4 OR attrib_7 = :prop4 AND value_7 >= :val4 OR attrib_8 = :prop4 AND value_8 >= :val4) AND (attrib_1 = :prop5 AND value_1 >= :val5 OR attrib_2 = :prop5 AND value_2 >= :val5 OR attrib_3 = :prop5 AND value_3 >= :val5 OR attrib_4 = :prop5 AND value_4 >= :val5 OR attrib_5 = :prop5 AND value_5 >= :val5 OR attrib_6 = :prop5 AND value_6 >= :val5 OR attrib_7 = :prop5 AND value_7 >= :val5 OR attrib_8 = :prop5 AND value_8 >= :val5) AND (attrib_1 = :prop6 AND value_1 >= :val6 OR attrib_2 = :prop6 AND value_2 >= :val6 OR attrib_3 = :prop6 AND value_3 >= :val6 OR attrib_4 = :prop6 AND value_4 >= :val6 OR attrib_5 = :prop6 AND value_5 >= :val6 OR attrib_6 = :prop6 AND value_6 >= :val6 OR attrib_7 = :prop6 AND value_7 >= :val6 OR attrib_8 = :prop6 AND value_8 >= :val6) AND (attrib_1 = :prop7 AND value_1 >= :val7 OR attrib_2 = :prop7 AND value_2 >= :val7 OR attrib_3 = :prop7 AND value_3 >= :val7 OR attrib_4 = :prop7 AND value_4 >= :val7 OR attrib_5 = :prop7 AND value_5 >= :val7 OR attrib_6 = :prop7 AND value_6 >= :val7 OR attrib_7 = :prop7 AND value_7 >= :val7 OR attrib_8 = :prop7 AND value_8 >= :val7) AND (attrib_1 = :prop8 AND value_1 >= :val8 OR attrib_2 = :prop8 AND value_2 >= :val8 OR attrib_3 = :prop8 AND value_3 >= :val8 OR attrib_4 = :prop8 AND value_4 >= :val8 OR attrib_5 = :prop8 AND value_5 >= :val8 OR attrib_6 = :prop8 AND value_6 >= :val8 OR attrib_7 = :prop8 AND value_7 >= :val8 OR attrib_8 = :prop8 AND value_8 >= :val8)) $limit"; $arr = array(":item_name" => $itemName, ":quality" => $Quality, ":type" => $Type, ":sub" => $sub_Type, ":prop1" => $itemAttrib1, ":val1" => $val_1, ":val2" => $val_2, ":val3" => $val_3, ":val4" => $val_4, ":val5" => $val_5, ":val6" => $val_6, ":val7" => $val_7, ":val8" => $val_8, ":prop2" => $itemAttrib2, ":prop3" => $itemAttrib3, ":prop4" => $itemAttrib4, ":prop5" => $itemAttrib5, ":prop6" => $itemAttrib6, ":prop7" => $itemAttrib7, ":prop8" => $itemAttrib8); $this->view->items = $this->database->DBQry($sql,$arr); $this->view->msg = "Successful Search"; $this->view->err = true; $this->view->render('Search/Index'); } } ?> here is the "Search/Index" View: <?php include_once("views/Header.php"); ?> <div class="container"> <?php if($this->err == true): ?> <div class="alert alert-success alert-dismissable"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> <?php echo $this->msg; ?> </div> <?php else: ?> <div class="alert alert-danger alert-dismissable"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> <?php echo $this->msg; ?> </div> <?php endif ?> <div class="well well-sm"> <div class="row col-xs-12"> <div class="btn-group"> <a class="btn btn-danger dropdown-toggle" data-toggle="dropdown" href="#" style="font-weight: normal;"><?php if ($url == '/us/sc') { ?>US Softcore<?php }elseif ($url == '/us/hc') { ?> US Hardcore <?php } ?> <span class="caret"></span> </a> <ul class="dropdown-menu open" style="padding: 5px;"> <li><a href="<?php echo $ahurl; ?>/sc">US Softcore</a></li> <li class="divider"></li> <li><a href="<?php echo $ahurl;?>/hc">US Hardcore</a></li> </ul> </div> </div> </div> <?php include("models/ItemSearch.php"); ?> <div class="row"> <div class="col-md-8"> <!-- Item --> <?php $count = 0; if (count($this->items)%3!=0) { //Append 1 or 2 items from start of array if needed } ?><div class="row"> <?php foreach ($this->items as $item): if (($count>0) and ($count%3==0)): ?></div><div class="row"><?php endif; ?><div class='col-md-4'> <div class="thumbnail"> <h4 <?php if ($item['quality'] == 'Legendary'): ?> class="item-title quality-orange" <?php elseif ($item['quality'] == 'Set'): ?> class="item-title quality-green" <?php elseif ($item['quality'] == 'Rare'): ?> class="item-title quality-yellow" <?php endif ?>><a class="item-title" style="text-decoration:none;" href="<?php echo $this->url; ?>Item-<?php echo $item['item_num']; ?>"><?php echo $item['item_name']; ?></a></h4> <a href="<?php echo $this->url; ?>Item-<?php echo $item['item_num']; ?>"> <img <?php if ($item['quality'] == 'Legendary'): ?> class="item-icon quality-orange" <?php elseif ($item['quality'] == 'Set'): ?> class="item-icon quality-green" <?php elseif ($item['quality'] == 'Rare'): ?> class="item-icon quality-yellow" <?php endif ?> src="<?php echo $this->url.$item['item_img']; ?>" align="left" /></a> <div class="caption"> <?php if ($item['armor'] == NULL){ echo ''; }else{ ?> <ul class="stat-basic"><li class="armor"><?php echo $item['armor']; ?></li>Armor</ul> <?php }if ($item['dps'] == NULL && $item['min_max'] == NULL && $item['aps'] == NULL){ echo ''; }else{ ?> <ul class="stat-basic"> <li class="dmg"><?php echo $item['dps']; ?></li><li class="dps"> Damage Per Second</li> <li><?php echo $item['min_max']; ?> Damage</li> <li><?php echo $item['aps']; ?> Attacks Per Second</li> </ul> <?php }?> <div class="prop"> <ul class="item-attrib"> <?php if($item['attrib_1'] == 'None' || $item['attrib_1'] == '' || $item['attrib_1'] == 'none' || $item['attrib_1'] == 'Has Sockets'){ echo ''; }else{ ?> <li><img src="<?php echo $this->url."img/bullet.gif"; ?>"> +<?php echo $item['value_1']; ?> <?php echo $item['attrib_1']; ?></li> <?php }if ($item['attrib_2'] == 'None' || $item['attrib_2'] == '' || $item['attrib_2'] == 'none' || $item['attrib_2'] == 'Has Sockets'){ echo ''; }else{ ?> <li><img src="<?php echo $this->url."img/bullet.gif"; ?>"> +<?php echo $item['value_2']; ?> <?php echo $item['attrib_2']; ?></li> <?php }if ($item['attrib_3'] == 'None' || $item['attrib_3'] == '' || $item['attrib_3'] == 'none' || $item['attrib_3'] == 'Has Sockets'){ echo ''; }else{ ?> <li><img src="<?php echo $this->url."img/bullet.gif"; ?>"> +<?php echo $item['value_3']; ?> <?php echo $item['attrib_3']; ?></li> <?php }if ($item['attrib_4'] == 'None' || $item['attrib_4'] == '' || $item['attrib_4'] == 'none' || $item['attrib_4'] == 'Has Sockets'){ echo ''; }else{ ?> <li><img src="<?php echo $this->url."img/bullet.gif"; ?>"> +<?php echo $item['value_4']; ?> <?php echo $item['attrib_4']; ?></li> <?php }if ($item['attrib_5'] == 'None' || $item['attrib_5'] == '' || $item['attrib_5'] == 'none' || $item['attrib_5'] == 'Has Sockets'){ echo ''; }else{ ?> <li><img src="<?php echo $this->url."img/bullet.gif"; ?>"> +<?php echo $item['value_5']; ?> <?php echo $item['attrib_5']; ?></li> <?php }if ($item['attrib_6'] == 'None' || $item['attrib_6'] == '' || $item['attrib_6'] == 'none' || $item['attrib_6'] == 'Has Sockets'){ echo ''; }else{ ?> <li><img src="<?php echo $this->url."img/bullet.gif"; ?>"> +<?php echo $item['value_6']; ?> <?php echo $item['attrib_6']; ?></li> <?php }if ($item['attrib_7'] == 'None' || $item['attrib_7'] == '' || $item['attrib_7'] == 'none' || $item['attrib_7'] == 'Has Sockets'){ echo ''; }else{ ?> <li><img src="<?php echo $this->url."img/bullet.gif"; ?>"> +<?php echo $item['value_7']; ?> <?php echo $item['attrib_7']; ?></li> <?php }if ($item['attrib_8'] == 'None' || $item['attrib_8'] == '' || $item['attrib_8'] == 'none' || $item['attrib_8'] == 'Has Sockets'){ echo ''; }else{ ?> <li><img src="<?php echo $this->url."img/bullet.gif"; ?>"> +<?php echo $item['value_8']; ?> <?php echo $item['attrib_8']; ?></li> <?php }if ($item['attrib_1'] == 'Has Sockets' && $item['value_1'] == 3){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_1'] == 'Has Sockets' && $item['value_1'] == 2){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_1'] == 'Has Sockets' && $item['value_1'] == 1){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_2'] == 'Has Sockets' && $item['value_2'] == 3){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_2'] == 'Has Sockets' && $item['value_2'] == 2){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_2'] == 'Has Sockets' && $item['value_2'] == 1){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_3'] == 'Has Sockets' && $item['value_3'] == 3){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_3'] == 'Has Sockets' && $item['value_3'] == 2){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_3'] == 'Has Sockets' && $item['value_3'] == 1){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_4'] == 'Has Sockets' && $item['value_4'] == 3){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_4'] == 'Has Sockets' && $item['value_4'] == 2){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_4'] == 'Has Sockets' && $item['value_4'] == 1){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_5'] == 'Has Sockets' && $item['value_5'] == 3){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_5'] == 'Has Sockets' && $item['value_5'] == 2){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_5'] == 'Has Sockets' && $item['value_5'] == 1){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_6'] == 'Has Sockets' && $item['value_6'] == 3){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_6'] == 'Has Sockets' && $item['value_6'] == 2){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_6'] == 'Has Sockets' && $item['value_6'] == 1){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_7'] == 'Has Sockets' && $item['value_7'] == 3){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_7'] == 'Has Sockets' && $item['value_7'] == 2){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_7'] == 'Has Sockets' && $item['value_7'] == 1){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_8'] == 'Has Sockets' && $item['value_8'] == 3){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_8'] == 'Has Sockets' && $item['value_8'] == 2){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php }elseif ($item['attrib_8'] == 'Has Sockets' && $item['value_8'] == 1){?> <li><img src="<?php echo $this->url."img/empty-socket.png"; ?>"> Empty Socket</li> <?php } ?> </ul> </div> </div> </div> </div><?php $count++; endforeach; ?> <!-- end item --> </div> </div> <ul class="pager"> <?php echo $this->first; echo $this->prev; echo $this->next; echo $this->count; echo $this->last; ?> </ul> </div> </div> </div> <?php include_once("views/Footer.php"); ?>
- 8 replies
-
- php
- pagination
-
(and 2 more)
Tagged with:
-
Hello. Im fairly new to php but i like to think im reasonably competent. To set the scene, ive got a website that displays, for simplicity, images. I also have some scripts that show this in a paginated form when they get above x number. If i merely had a blank page(s) with lists of images that broke into new page every 25th image then my script could handle that without an issue. However, as you may have already guessed, it is not just quite as simple as that. I also have a search function on this page. As a separate entity it works very well, and its able to search the database correctly for the search terms. It can also show the data in paginated form - ie, if i have 24 images selected from the search terms then it will show that there is only 1 page, if my settings dictate a page break on the 25th image. The issue arises in a few scenarios: a) if someone has searched, is given a page of results, and then clicks the "1st page" link the pagination scripts create, then the search is lost and it returns to the complete list of unfiltered images. b) If I have more than, for example 27 images (ie a need for TWO pages post search), then when someone clicks the "2nd page" link, instead of seeing page 2 of the searched for images, they see page two of the unfiltered image, ie, it seems that the script is unable to carry the search terms across pages and act upon them. So, in simple form, I have a pagination script that paginates, and a search function that searches, but im having trouble integrating them both. Below are my scripts: This creates the page numbers at the bottom: (NB i have tried to alter the link url by appending both page number and the "lookup" (search terms). <?php if ($totalcountplus >= 1 && $page <= $totalcountplus) { for ($x = 1; $x<=$totalcountplus; $x++) { echo ($x == $page) ? '<strong><a href="?page='.$x.'&?lookup='.$searchword.'">'.$x.'</a></strong> ' : '<a href="?page='.$x.'&?lookup='.$searchword.'">'.$x.'</a> ';}} ?> Here we have the actual script that sorts the pagination: <?php $searchword = $_GET['lookup']; $expsearchword = explode(" ", $searchword); $searchquery = "SELECT DISTINCT user_id FROM `images` WHERE "; $searchquerytwo = "SELECT COUNT(DISTINCT user_id) FROM images WHERE "; foreach ($expsearchword as $item) { $t++; if ($t == 1) $searchquery .= "`description` LIKE '%$item%' OR `keywords` LIKE '%$item%'"; else $searchquery .= "OR `description` LIKE '%$item%' OR `keywords` LIKE '%$item%'"; } foreach ($expsearchword as $item) { $r++; if ($r == 1) $searchquerytwo .= "`description` LIKE '%$item%' OR `keywords` LIKE '%$item%'"; else $searchquerytwo .= "OR `description` LIKE '%$item%' OR `keywords` LIKE '%$item%'"; } $per_page = 25; $page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1; $start = ($page - 1) * $per_page; $totalcount = mysql_query($searchquerytwo); $totalcountarray = mysql_fetch_array($totalcount); $totalcountplus = ceil(mysql_result($totalcount, 0) / $per_page); $totalcountone = mysql_query("$searchquery LIMIT $start, $per_page"); while($totalcountplusone = mysql_fetch_array($totalcountone)) { ; $usercountone =$totalcountplusone['0']; } ?> I also have this while loop running on another page. its here for info only, and i dont think its contributing to my issues: $allimagesone = mysql_query("$searchquery LIMIT $start, $per_page"); while($airesult = mysql_fetch_assoc($allimagesone)) { ETC ETC ETC ; } ?> I know this is pretty long winded but i hope you guys can help me out because im a real loss as to how to combine the two functions successfully. Basically i think it boils down to getting the url to "remember" both the page number AND the search terms, and im not quite sure how to do that successfully. All advice is welcome, thanks in advice.
- 3 replies
-
- php
- search engine
-
(and 1 more)
Tagged with:
-
I want to have my results slide out and slide in just like a carousel. So my results are 3x3, and then whenever you click next, the existing results slide out to the left, and at the same time the new results slide in from the right hand side. If this is done then would it mean I have to download all the results, so they are stored, and can thus slide in immediately, without an ajax load? Or is there some other amazing way to accomplish a task like this?
- 3 replies
-
- pagination
- carousel
-
(and 1 more)
Tagged with:
-
Hi, I have cobbled together the code from two tutorials, both of which work superbly on their own, but I must have something wrong in the code because together they don't work. I have a database of chillies which is searchable. I want to add pagination when the results returned exceed 10. The problem is the first page of results returns 10 as it should, and at the bottom of the page there is the option to go to page two or next, but when you do, page 2 has no results and when you return to page one there are no results either. The code is as follows; <h1>Chilli Search Results</h1> <?php // Initilise search output variable $search_output = ""; // Process the search query if(isset($_POST['searchquery'])) { // Filter user input $searchquery = preg_replace('#[^a-z 0-9?]#i', '', $_POST['searchquery']); $heat = $_POST['heat']; // Select Database mysql_select_db("allotmen_content") or die (mysql_error()); if($heat != 'any'){ $sqlcommand = "SELECT id, image1, common_name, url, url_short FROM chillies WHERE common_name LIKE '%$searchquery%' AND heat = '$heat'"; }else{ $sqlcommand = "SELECT id, image1, common_name, url, url_short FROM chillies WHERE common_name LIKE '%$searchquery%'"; } $query = mysql_query($sqlcommand) or die(mysql_error()); $count = mysql_num_rows($query); if(empty($_POST['searchquery'])) { // If search box is empty echo 'Search box can not be empty. Please go back and enter some text <a href="chillies-homepage.php">BACK</a> <br /><br />'; // If count is greater than 0 }else if($count > 0) { $search_output .= "<hr /> $count Results for <strong>$searchquery</strong><hr /><br /><br />"; if (isset($_GET['pn'])) { // Get pn from URL vars if it is present $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); // filter everything but numbers for security(new) //$pn = ereg_replace("[^0-9]", "", $_GET['pn']); // filter everything but numbers for security(deprecated) } else { // If the pn URL variable is not present force it to be value of page number 1 $pn = 1; } //This is where we set how many database items to show on each page $itemsPerPage = 10; // Get the value of the last page in the pagination result set $lastPage = ceil($count / $itemsPerPage); // Be sure URL variable $pn(page number) is no lower than page 1 and no higher than $lastpage if ($pn < 1) { // If it is less than 1 $pn = 1; // force if to be 1 } else if ($pn > $lastPage) { // if it is greater than $lastpage $pn = $lastPage; // force it to be $lastpage's value } // This creates the numbers to click in between the next and back buttons // This section is explained well in the video that accompanies this script $centerPages = ""; $sub1 = $pn - 1; $sub2 = $pn - 2; $add1 = $pn + 1; $add2 = $pn + 2; if ($pn == 1) { $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; } else if ($pn == $lastPage) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; } else if ($pn > 2 && $pn < ($lastPage - 1)) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 . '">' . $sub2 . '</a> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 . '">' . $add2 . '</a> '; } else if ($pn > 1 && $pn < $lastPage) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; } // This line sets the "LIMIT" range... the 2 values we place to choose a range of rows from database in our query $limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage; // Now we are going to run the same query as above but this time add $limit onto the end of the SQL syntax // $sql2 is what we will use to fuel our while loop statement below $sql2 = mysql_query("$sqlcommand ORDER BY common_name ASC $limit"); $paginationDisplay = ""; // Initialize the pagination output variable // This code runs only if the last page variable is ot equal to 1, if it is only 1 page we require no paginated links to display if ($lastPage != "1"){ // This shows the user what page they are on, and the total number of pages $paginationDisplay .= 'Page <strong>' . $pn . '</strong> of ' . $lastPage. ' '; // If we are not on page 1 we can place the Back button if ($pn != 1) { $previous = $pn - 1; $paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '"> Back</a> '; } // Lay in the clickable numbers display here between the Back and Next links $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>'; // If we are not on the very last page we can place the Next button if ($pn != $lastPage) { $nextPage = $pn + 1; $paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextPage . '"> Next</a> '; } } while($row = mysql_fetch_array($sql2)) { $id = $row["id"]; $image = $row["image1"]; $title = $row["common_name"]; $url = $row["url"]; $url_short = $row["url_short"]; $search_output .= "<a href=\"$url_short\"><img src=\"images/$image\" width=\"100px\" height=\"100px\"/></a> $title - $url <br /><br />"; } // Close while // If no results are found } else { $search_output = "<hr /><br /> Sorry, there are no results for <strong>$searchquery</strong>. <br /><br />Try entering <strong>$searchquery</strong> again but this time select <strong>'ANY HEAT'</strong> as the Heat Level<br /><br /><hr />"; } } ?> <?php echo $search_output; ?> <br /> <?php echo $paginationDisplay; ?> I'm guessing I have have something not quite right, I just can't see it. The page itself can been seen here http://www.allotment-web.org/chillies-homepage.php Search just the letter 'a' to bring more than 10 results and you'll see the issue. There seems little point increasing the number of varieties until I fix this pagination. Any help greatly appreciated. Richard
- 9 replies
-
- pagination
- search
-
(and 2 more)
Tagged with:
-
Hi I have a list of youtube videos in a flat file database. I would like to print a thumbnail of these videos out to the end user in a table. The results need to have pagination as well as a dynamic table so i can display say 3 rows and 3 columns per page. The column amount will also need to be adjustable in case i wish to change the columns from 3 to 4 for example: $video_file_data[]; //This is the array in which all video info will be stored $start = $_REQUEST['start']; //pagination setting $videos_per_page = 9; //Show 9 Vids per page $table_colums = 3; //Amount of columns needed to display results per page $num = count ($video_file_data); //Number of lines in data array $max_pages = @ceil($num / $videos_per_page); //Maximum number of Pages $cur = @ceil($start / $videos_per_page)+1; for($i=$start;$i<min($num,($start+$videos_per_page)+0);$i++) { list($date_added, $video_title, $youtube_url) = explode('|', trim($video_file_data[$i])); // <--- Table needs to go } The info stored in $video_file_data[] would look something like this: date 1."|".title 1."|".youtube url 1 date 2."|".title 2."|".youtube url 2 date 3."|".title 3."|".youtube url 3 date 4."|".title 4."|".youtube url 4 Many thanks for the help
- 6 replies
-
- pagination
- dynamic
-
(and 2 more)
Tagged with:
-
I have two PHP objects if(function_exists('wp_commentnavi')) { wp_commentnavi(); } which is the comment pagination and if(function_exists('wp_commentnavi_all_comments_link')) { wp_commentnavi_all_comments_link(); } which is the all comments link. I would like the second, all the comments link, to be only displayed if a) there are more than x comments OR b) if the comment pagination isn't displayed neither should the all comments link. Essentially I want to say display all comments link if there are more than x comments, if not don't display all comments link. Anyone know the code required to do this? Thanks in advance!
-
I am currently using the plugin WP-CommentNavi for comments pagination but whenever a page is clicked it goes to the highest comments page (oldest comments). My comments are purposely displayed newest first and therefore I need the default pagination page to be 1 whenever a link is clicked. I notice there is the same default for other pagination plugins too whereby the highest pagination page (ie if there are 5 pages) page 5 is displayed. At the moment when I load page tellhi####.com/newcastle the page that will be loaded is tellhi####.com/newcastle/comment-page-2/ whereas I want tellhi####.com/newcastle/comment-page-1/ to be loaded I can't be sure this is the relevant code to what I am trying to achieve but I feel the answer might lie in here (below). If not, please tell me and disregard this code. ### Function: Comment Navigation: Boxed Style Paging function wp_commentnavi($before = '', $after = '') { global $wp_query; $comments_per_page = intval(get_query_var('comments_per_page')); $paged = intval(get_query_var('cpage')); $commentnavi_options = get_option('commentnavi_options'); $numcomments = intval($wp_query->comment_count); $max_page = intval($wp_query->max_num_comment_pages); if(empty($paged) || $paged == 0) { $paged = 1; } $pages_to_show = intval($commentnavi_options['num_pages']); $pages_to_show_minus_1 = $pages_to_show-1; $half_page_start = floor($pages_to_show_minus_1/2); $half_page_end = ceil($pages_to_show_minus_1/2); $start_page = $paged - $half_page_start; if($start_page <= 0) { $start_page = 1; } $end_page = $paged + $half_page_end; if(($end_page - $start_page) != $pages_to_show_minus_1) { $end_page = $start_page + $pages_to_show_minus_1; } if($end_page > $max_page) { $start_page = $max_page - $pages_to_show_minus_1; $end_page = $max_page; } if($start_page <= 0) { $start_page = 1; } if($max_page > 1 || intval($commentnavi_options['always_show']) == 1) { $pages_text = str_replace("%CURRENT_PAGE%", number_format_i18n($paged), $commentnavi_options['pages_text']); $pages_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pages_text); echo $before.'<div class="wp-commentnavi">'."\n"; switch(intval($commentnavi_options['style'])) { case 1: if(!empty($pages_text)) { echo '<span class="pages">'.$pages_text.'</span>'; } if ($start_page >= 2 && $pages_to_show < $max_page) { $first_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $commentnavi_options['first_text']); echo '<a href="'.clean_url(get_comments_pagenum_link()).'" class="first" title="'.$first_page_text.'">'.$first_page_text.'</a>'; if(!empty($commentnavi_options['dotleft_text'])) { echo '<span class="extend">'.$commentnavi_options['dotleft_text'].'</span>'; } } previous_comments_link($commentnavi_options['prev_text']); for($i = $start_page; $i <= $end_page; $i++) { if($i == $paged) { $current_page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $commentnavi_options['current_text']); echo '<span class="current">'.$current_page_text.'</span>'; } else { $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $commentnavi_options['page_text']); echo '<a href="'.clean_url(get_comments_pagenum_link($i)).'" class="page" title="'.$page_text.'">'.$page_text.'</a>'; } } next_comments_link($commentnavi_options['next_text'], $max_page); if ($end_page < $max_page) { if(!empty($commentnavi_options['dotright_text'])) { echo '<span class="extend">'.$commentnavi_options['dotright_text'].'</span>'; } $last_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $commentnavi_options['last_text']); echo '<a href="'.clean_url(get_comments_pagenum_link($max_page)).'" class="last" title="'.$last_page_text.'">'.$last_page_text.'</a>'; } break; case 2; echo '<form action="'.admin_url('admin.php?page='.plugin_basename(__FILE__)).'" method="get">'."\n"; echo '<select size="1" onchange="document.location.href = this.options[this.selectedIndex].value;">'."\n"; for($i = 1; $i <= $max_page; $i++) { $page_num = $i; if($page_num == 1) { $page_num = 0; } if($i == $paged) { $current_page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $commentnavi_options['current_text']); echo '<option value="'.clean_url(get_comments_pagenum_link($page_num)).'" selected="selected" class="current">'.$current_page_text."</option>\n"; } else { $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $commentnavi_options['page_text']); echo '<option value="'.clean_url(get_comments_pagenum_link($page_num)).'">'.$page_text."</option>\n"; } } echo "</select>\n"; echo "</form>\n"; break; } echo '</div>'.$after."\n"; } } In short I need, anytime a page is clicked, for the comments pagination to be on page 1, not the highest page available. Just so you know I have tried the discussion settings on the wordpress dashboard. Nothing on google either! Failing a full answer, does anyone know the actual php code that determines what pagination page is loaded by default? I received this response via an e-mail but due to my PHP knowledge am unable to implement it, any ideas? ... Just reverse the loop. That'll fix it. Here's the relevant part: http://pastie.org/8166399 You need to go back, i.e. use $i-- Hope I have been clear in my question! Thanks in advance, Paul
- 1 reply
-
- pagination
- loop
-
(and 3 more)
Tagged with:
-
Greetings all, So, I'm working on my page navigation and I'm having a little trouble with my math here. It's probably a brain freeze from too much coding in one day but anyhow. What I'm trying to get my code to do is always show 9 pages and never show anymore then 9 pages in the navigation. Unfortunately that's not the result that I am getting with this script. // List page selectors. for($j = max(1, $current_page - ; $j <= min($current_page + 8, $total_pages); $j++) { $p = $j; echo "<a href='?p=" . $p . "'>" . $p . "</a> "; } I have a different script for the first page, previous page, next page and last page links. They all work fine of course since those are super easy scripts. Any help would be appreciated. Best Regards, Nightasy
-
So, I'm playing around with pagination. The script I wrote determines how many images are in a folder, throws them into an array and then splits them up so that only 9 are displayed per page. It all works great except for that if a page doesn't have 9 images on it I get this error. Notice: Undefined offset:... blah blah blah I already know that it has to do with the array not having an existing field and I am supposed to use an isset to check that the array field even exists. But everywhere I have tried to put it, it doesn't work and actually causes none of the images to appear and only the errors. If anyone could show me what I'm doing wrong here I'd really appreciate it. // Create Array $files = array(); if( is_dir( $thumbs_dir ) ) { if( $handle = opendir( $thumbs_dir ) ) { while( ( $file = readdir( $handle ) ) !== false ) { if( $file != "." && $file != ".." ) { array_push( $files, $file ); } } closedir( $handle ); } } // Set images per page and determine total pages. $page_size = 9; $total_pages = ceil( count( $files ) / $page_size ); // Create divs. echo '<div id="centerwrapper">'; echo '<div id="left_div">'; // Determine Page and Display. if( isset( $_GET['p'] ) ) { $current_page = $_GET['p']; if( $current_page > $total_pages ) { $current_page = $total_pages; } } else { $current_page = 1; } $start = ( $current_page * $page_size ) - $page_size; // Title Gallery and display page number. echo $_SESSION['username'] . "'s Images<br>"; echo "Page " . $current_page . " of " . $total_pages . "<br><br>\n\n" ; // List page selectors. for( $j=0; $j<$total_pages; $j++ ) { $p = $j + 1; print( "<a href='?p=" . $p . "'>" . $p . "</a> " ); } echo "<br><br>"; echo "<hr>"; for( $i=$start; $i<$start + $page_size; $i++ ) { /*Verify file exists, if exists echo file.*/ if( is_file( $thumbs_dir . $files[$i] ) ) { $thumbnail_image = $thumbs_dir.$file[$i]; $medium_image = $medium_dir.$file[$i]; echo '<a class="DDImage" href="'.$medium_image . $files[$i] .'" rel="enlargeimage" rev="targetdiv:loadareatest,trigger:click,preload:none,fx:reveal,link:'.$images_dir . $files[$i] .'"><img class="photo-link" src="'.$thumbnail_image . $files[$i] .'" /></a>'; } } echo '</div>'; echo '</div>'; echo '<div id="loadareatest"></div>'; Oh and if you see a variable that's not being used it's because this is only part of the entire code that I have planned for this page. Best Regards, Nightasy
-
Hiya i was hoping for some help with my pagination. I don't quite understand why its not working. I've tried echoing out the $paginationDisplay and it doesn't display anything so its not getting its value. <?php // Script Error Reporting error_reporting(E_ALL); ini_set('display_errors', '1'); ?> <?php // Run a select query to get my letest 6 items // Connect to the MySQL database include "storescripts/connect_to_mysql.php"; $dynamicList = ""; $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC"); $productCount = mysql_num_rows($sql); // count the output amount //////////////////////////////////// Pagination Logic //////////////////////////////////////////////////////////////////////// $nr = $productCount; // Get total of Num rows from the database query if (isset($_GET['pn'])) { // Get pn from URL vars if it is present $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); // filter everything but numbers for security(new) //$pn = ereg_replace("[^0-9]", "", $_GET['pn']); // filter everything but numbers for security(deprecated) } else { // If the pn URL variable is not present force it to be value of page number 1 $pn = 1; } //This is where we set how many database items to show on each page $itemsPerPage = 10; // Get the value of the last page in the pagination result set $lastPage = ceil($nr / $itemsPerPage); // Be sure URL variable $pn(page number) is no lower than page 1 and no higher than $lastpage if ($pn < 1) { // If it is less than 1 $pn = 1; // force if to be 1 } else if ($pn > $lastPage) { // if it is greater than $lastpage $pn = $lastPage; // force it to be $lastpage's value } // This creates the numbers to click in between the next and back buttons // This section is explained well in the video that accompanies this script $centerPages = ""; $sub1 = $pn - 1; $sub2 = $pn - 2; $add1 = $pn + 1; $add2 = $pn + 2; if ($pn == 1) { $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; } else if ($pn == $lastPage) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; } else if ($pn > 2 && $pn < ($lastPage - 1)) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 . '">' . $sub2 . '</a> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 . '">' . $add2 . '</a> '; } else if ($pn > 1 && $pn < $lastPage) { $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> '; $centerPages .= ' <span class="pagNumActive">' . $pn . '</span> '; $centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> '; } // This line sets the "LIMIT" range... the 2 values we place to choose a range of rows from database in our query $limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage; // Now we are going to run the same query as above but this time add $limit onto the end of the SQL syntax // $sql2 is what we will use to fuel our while loop statement below $sql2 = mysql_query("SELECT * FROM products ORDER BY date_added DESC $limit"); //////////////////////////////// END Pagination Logic //////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////// Pagination Display Setup ///////////////////////////////////////////////////////////////////// $paginationDisplay = ""; // Initialize the pagination output variable // This code runs only if the last page variable is ot equal to 1, if it is only 1 page we require no paginated links to display if ($lastPage != "1"){ // This shows the user what page they are on, and the total number of pages $paginationDisplay .= 'Page <strong>' . $pn . '</strong> of ' . $lastPage. ' '; // If we are not on page 1 we can place the Back button if ($pn != 1) { $previous = $pn - 1; $paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '"> Back</a> '; } // Lay in the clickable numbers display here between the Back and Next links $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>'; // If we are not on the very last page we can place the Next button if ($pn != $lastPage) { $nextPage = $pn + 1; $paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextPage . '"> Next</a> '; } } ///////////////////////////////////// END Pagination Display Setup / echo $paginationDisplay; if ($productCount > 0) { while($row = mysql_fetch_array($sql2)){ $id = $row["id"]; $product_name = $row["product_name"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="6"> <tr> <td width="17%" valign="top"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" /></a></td> <td width="83%" valign="top">' . $product_name . '<br /> £' . $price . '<br /> <a href="product.php?id=' . $id . '">View Product Details</a></td> </tr> <tr><td>' .$paginationDisplay. '</td></tr> </table>'; } } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Store Home Page</title> <link rel="stylesheet" href="style/style.css" type="text/css" media="screen" /> </head> <body> <center> <div align="center" id="mainWrapper"> <?php include_once("template_header.php");?> <div id="pageContent"> <table width="100%" border="0" cellspacing="0" cellpadding="10"> <tr> <td width="32%" valign="top"><h3>What the Hell?</h3> <p>side text</p></td> <td width="35%" valign="top"><h3>Latest Designer Fashions</h3> <p><?php echo $dynamicList; ?><br /> </p> <p><br /> </p></td> <td width="33%" valign="top"><h3>Handy Tips</h3> <p>side html text</p></td> </tr> </table> </div> <?php include_once("template_footer.php");?> </div></center> </body> </html> If you can help me fix it I'd be ever so grateful. Thank you
-
Dear all, Here is my scenario, I have a php page called index.php which is linked to dashboard. At the index page i will have 40-50 href's each with a id like dashboard.php/subcat=1 When a user click's particular href they will be forwarded to a page called dashboard and there i get this id. $subcat=$_REQUEST['subcat']; This dashboard is dynamic. In this page i have three different div's. Each with different query and result display. For example: My first div has a query and some 50 results. I want a display first four rows and remaining as a ajax pagination. similarly for the other two div's. There is no problem in using ajax pagination because it will be executed in different page and result will be display here. But the real problem is in each of my query i should pass the original subcat id which is what make the dashboard dynamic. Now, i need someway to pass this dynamic id for my external pagination for each query.
- 1 reply
-
- php
- pagination
-
(and 2 more)
Tagged with:
-
Hey guys, i am trying to create some pagination within my page to allow a user to go through my entire catalog or data from my database. i have everything working correctly ( kinda ) , but for some reason when i then click on a link to get me around the pages, i get some problems. VARIABLES TO CREATE PAGINATION $per_page = 25; $page = (isset($_GET['page'])) ? (int) $_GET['page'] : 1; $start = ($page - 1 ) * $per_page; CONDITIONAL TO SEE WHERE THE USER IS AND WHAT TYPE OF INFO THEY WANT if(in_array($person_type,$all_links) === true) { // genre matches array of genres $query = "SELECT * FROM `content` WHERE `person_type` LIKE '%$type%' AND `is_type`=0 AND is_rating AND isdb_votes >10000 ORDER BY isdb_join_date DESC LIMIT $start , $per_page "; <--- this is where variables are being presented to track the position. //echo $query; } if (in_array($letter, $all_links) === true){ $query = "SELECT * FROM `content` WHERE `imdb_title` LIKE '$letter%' AND `is_type`=0 AND is_rating AND isdb_votes >10000 ORDER BY isdb_join_date DESC LIMIT $start , $per_page "; <--- this is where variables are being presented to track the position. //echo $query; } if (in_array($year, $all_links) === true) { $query = "SELECT * FROM `content` WHERE `imdb_release_date` LIKE '%$year%' AND `is_type`=0 AND is_rating AND isdb_votes >10000 ORDER BY isdb_join_date DESC LIMIT $start , $per_page "; <--- this is where variables are being presented to track the position.//echo $query; } THIS THEN QUERIES THE QUERY FROM WHICHEVER CONDITIONAL IS PASSED $links = mysql_query($query); DIV WHERE PAGINATION IS <div> <? $pages = ceil(mysql_result($links, 0) / $per_page); if ($pages >= 1) { for ($x = 1; $x<=$pages; $x++ ) { if (isset($_GET['genre']) === true) { echo '<a href = "browse.php?type='.$type.'&page='.$x.'">'.$x.' '; } else if (isset($_GET['letter']) === true) { echo '<a href = "browse.php?type='.$type.'&letter='.$letter.'&page='.$x.'">'.$x.' '; } else if (isset($_GET['year']) === true) { echo '<a href = "browse.php?type='.$type.'&year='.$year.'&page='.$x.'">'.$x.' '; } } } ?> </div> THE ISSUE: i get the links to show up and they all direct me to the correct query and connection to the Database. the first couple pages will work correctly, and there are no issues with the pagination. if you see above there is a variables called $pages = which spits out the number of pages total needed depending on how many items i want to be outputted. ( i.e 25 ). so one category would have 100 pages , one would have 300, and some even with say 10 pages. Now when i click on say page 10 of 100 that is being echoed the query fails. not only does the query fail , but the amount of pages numbers being outputted changes for the same directory. so category 1 with 100 pages then becomes category 1 with 67 pages. this makes no sense to me as to why this is happening. i also cant seem to understand also why i keep getting an error of to my understanding the query is no longer returning true , and now there are zero rows returning, yet if there was no more data to be given , why is there a page number being outputted in the first place ? any suggestions to this problem ? any help would be greatly appreciated.
- 1 reply
-
- php
- pagination
-
(and 2 more)
Tagged with:
-
I tried a simple pagination. As a web hobbyist, i tried to visualize the whole aspect first, and then tried to implement them. I need experts opinion. Is my approach okay? How i can i modify it (i am sure it is too simple an approach, and can be modified)? 1) i keep an MyArray class at my lib folder and name it commonfunction.php. it goes like this: class myArray implements ArrayAccess { protected $array = array(); function offsetSet($offset, $value) { if(!is_numeric($offset)){ throw new Exception("Invalid key {$offset}") ; } $this->array[$offset] = $value; } function offsetGet($offset) { return $this->array[$offset]; } function offsetUnset($offset) { unset ($this->array[$offset]); } function offsetExists($offset) { return array_key_exists($this->array, $offset); } } 2) Next, i have a published comments table, that i want to paginate. To start with, i create a pagination1.php page. The code is like this: <?php include_once 'lib/commonfunction.php'; if(!isset ($_REQUEST['next'])){ echo ""; } mysql_connect('localhost', 'root', ''); mysql_select_db('appababa'); ////////////////////////////////////////////////////////////////////////////////// //trying pagination/// $myrow = new myArray(); $myquery = mysql_query("SELECT * FROM comments WHERE `comments`.`is_published`='Y'"); $myresults = array(); while ($myrow = mysql_fetch_array($myquery)) { $myresults[]=$myrow[0]; } foreach ($myresults as $key=>$value) { $myquery = mysql_query("SELECT * FROM comments WHERE `comments`.`id`='".$value."'"); while ($fullrow = mysql_fetch_array($myquery)) { //echo "Description : ".$fullrow['description']."<br>"; if ($fullrow['id']==1){ echo "Description : ".$fullrow['description']."<br>"; $next=next($fullrow); $next++; echo "<a href='http://localhost/ClassesAndObjects/pagination2.php?next={$next}'>NEXT</a>"; } } } ?> 3) Next i have a pagination2.php. The code is like this: <?php include_once 'lib/commonfunction.php'; if(!isset ($_REQUEST['next'])){ echo ""; } mysql_connect('localhost', 'root', ''); mysql_select_db('appababa'); ////////////////////////////////////////////////////////////////////////////////// //trying pagination/// $myrow = new myArray(); $myquery = mysql_query("SELECT * FROM comments WHERE `comments`.`is_published`='Y'"); $myresults = array(); while ($myrow = mysql_fetch_array($myquery)) { $myresults[]=$myrow[0]; } $present=0; if(isset ($_REQUEST['next'])) $present = $_REQUEST['next']; if ($present==0){ header('Location:http://localhost/ClassesAndObjects/pagination1.php'); } $myquery = mysql_query("SELECT * FROM comments WHERE `comments`.`id`='".$present."'"); while ($fullrow = mysql_fetch_array($myquery)) { //echo "Description : ".$fullrow['description']."<br>"; if ($fullrow['id']==$present){ echo "Description : ".$fullrow['description']."<br>"; $next=next($fullrow); $next++; echo "<a href='http://localhost/ClassesAndObjects/pagination2.php?next={$next}'>NEXT</a>"; echo " ------ "; $prev=prev($fullrow); $prev--; echo "<a href='http://localhost/ClassesAndObjects/pagination3.php?prev={$prev}'>PREV</a>"; } } $row = new myArray(); $query1 = mysql_query("SELECT * FROM comments WHERE `comments`.`is_published`='Y'"); $results = array(); while ($row = mysql_fetch_array($query1)) { $results[]=$row[0]; //echo $row['description']." = "."<a href='http://localhost/ClassesAndObjects/update.php?id={$row['id']}'>UNPUBLISH</a>"."<br>"; } //echo "Total number of published comments : ".count($results); $count=count($results); $count++; if ($present==$count){ header('Location:http://localhost/ClassesAndObjects/pagination1.php'); } ?> 3) Next i have pagination3.php. The code is like this: <?php include_once 'lib/commonfunction.php'; if(!isset ($_REQUEST['prev'])){ echo ""; } mysql_connect('localhost', 'root', ''); mysql_select_db('appababa'); ////////////////////////////////////////////////////////////////////////////////// //trying pagination/// $myrow = new myArray(); $myquery = mysql_query("SELECT * FROM comments WHERE `comments`.`is_published`='Y'"); $myresults = array(); while ($myrow = mysql_fetch_array($myquery)) { $myresults[]=$myrow[0]; } $present=0; if(isset ($_REQUEST['prev'])) $present = $_REQUEST['prev']; if ($present==0){ header('Location:http://localhost/ClassesAndObjects/pagination1.php'); } $myquery = mysql_query("SELECT * FROM comments WHERE `comments`.`id`='".$present."'"); while ($fullrow = mysql_fetch_array($myquery)) { //echo "Description : ".$fullrow['description']."<br>"; if ($fullrow['id']==$present){ echo "Description : ".$fullrow['description']."<br>"; $next=next($fullrow); $next++; echo "<a href='http://localhost/ClassesAndObjects/pagination2.php?next={$next}'>NEXT</a>"; echo " ------ "; $prev=prev($fullrow); $prev--; echo "<a href='http://localhost/ClassesAndObjects/pagination3.php?prev={$prev}'>PREV</a>"; } } ?> Finally, it works faultlessly. There is apparently no problem. It is based on mainly three array functions, count(), next(), and prev(). I tried to avoid mathematical calculation as much as possible. I need your opinion. Many thanks.
-
Hello, i have a question about the results in the browser where you search. I want that this, Search+source+code&page=36 Search+source+code&page=72 Search+source+code&page=108 to change it like this, when you click next or 2 3 4 5 etc Search+source+code&page=2 Search+source+code&page=3 Search+source+code&page=4 is that possible ? here below the complete script <?php $button = $_GET ["submit"]; $search = $_GET ["search"]; if(strlen($search)<=1) echo "Search term too short"; else{ echo "You searched for <b>$search</b> <hr size='1'></br>"; mysql_connect("mysql_host_name","mysql_username","mysql_password"); mysql_select_db("database_name"); $search_exploded = explode (" ", $search); foreach($search_exploded as $search_each) { $x++; if($x==1) $construct .="title LIKE '%$search_each%'"; else $construct .="AND title LIKE '%$search_each%'"; } $constructs ="SELECT * FROM database_table_name WHERE $construct"; $run = mysql_query($constructs); $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "Sorry, there are no matching result for <b>$search</b>.</br></br>1. Try more general words. for example: If you want to search 'how to create a website' then use general keyword like 'create' 'website'</br>2. Try different words with similar meaning</br>3. Please check your spelling"; else { echo "$foundnum results found !<p>"; $per_page = 36; $page = $_GET["page"]; $max_pages = ceil($foundnum / $per_page); if(!$page) $page=0; $getquery = mysql_query("SELECT * FROM database_table_name WHERE $construct LIMIT $page, $per_page"); while($runrows = mysql_fetch_assoc($getquery)) { $title = $runrows ["title"]; $desc = $runrows ["description"]; $url = $runrows ["url"]; echo " <a href='$url'><b>$title</b></a><br> $desc<br> <a href='$url'>$url</a><p> "; } //Pagination pages echo "<center>"; $prev = $page - $per_page; $next = $page + $per_page; $adjacents = 3; $last = $max_pages - 1; if($max_pages > 1) { //previous button if (!($page<=0)) echo " <a href='search.php?search=$search&submit=Search+source+code&page=$prev'>Prev</a> "; //pages if ($max_pages < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up { $i = 0; for ($counter = 1; $counter <= $max_pages; $counter++) { if ($i == $page){ echo " <a href='search.php?search=$search&submit=Search+source+code&page=$i'><b>$counter</b></a> "; } else { echo " <a href='search.php?search=$search&submit=Search+source+code&page=$i'>$counter</a> "; } $i = $i + $per_page; } } elseif($max_pages > 5 + ($adjacents * 2)) //enough pages to hide some { //close to beginning; only hide later pages if(($page/$per_page) < 1 + ($adjacents * 2)) { $i = 0; for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($i == $page){ echo " <a href='search.php?search=$search&submit=Search+source+code&page=$i'><b>$counter</b></a> "; } else { echo " <a href='search.php?search=$search&submit=Search+source+code&page=$i'>$counter</a> "; } $i = $i + $per_page; } } //in middle; hide some front and some back elseif($max_pages - ($adjacents * 2) > ($page / $per_page) && ($page / $per_page) > ($adjacents * 2)) { echo " <a href='search.php?search=$search&submit=Search+source+code&page=0'>1</a> "; echo " <a href='search.php?search=$search&submit=Search+source+code&page=$per_page'>2</a> .... "; $i = $page; for ($counter = ($page/$per_page)+1; $counter < ($page / $per_page) + $adjacents + 2; $counter++) { if ($i == $page){ echo " <a href='search.php?search=$search&submit=Search+source+code&page=$i'><b>$counter</b></a> "; } else { echo " <a href='search.php?search=$search&submit=Search+source+code&page=$i'>$counter</a> "; } $i = $i + $per_page; } } //close to end; only hide early pages else { echo " <a href='search.php?search=$search&submit=Search+source+code&page=0'>1</a> "; echo " <a href='search.php?search=$search&submit=Search+source+code&page=$per_page'>2</a> .... "; $i = $page; for ($counter = ($page / $per_page) + 1; $counter <= $max_pages; $counter++) { if ($i == $page){ echo " <a href='search.php?search=$search&submit=Search+source+code&page=$i'><b>$counter</b></a> "; } else { echo " <a href='search.php?search=$search&submit=Search+source+code&page=$i'>$counter</a> "; } $i = $i + $per_page; } } } //next button if (!($page >=$foundnum-$per_page)) echo " <a href='search.php?search=$search&submit=Search+source+code&page=$next'>Next</a> "; } echo "</center>"; } } ?> Thank`s in advance.
-
Hi Im new here.. Im a PHP noo-b i have this simple code with sorting and pagination with dummy data (firstname,lastname,age) I would like to add some simple search to it..im not sure if im doing this right currentlty the search is not working properly for testing purpose, right now i limit 3 records per page a. when i search record and search result is display..Pagination link is still display even i have only 1record search result b. if i have 4 records found, when i click the 2nd page, the search result is gone and table is back to default view c. in table default view, clicking 2nd page and try to search record, records are not found because its looking under the 2nd page and not all of the table sorry for my English <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>Paging</title> </head> <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"> <form method="post" action="" > <br />Search <input type="text" name="search" /> <input type="submit" value="Search"/></form><br /> <?php require "connect.php"; // All database details will be included here // define values the rest of the code uses $table = 'person'; // database table name $sorts = array('firstname'=>'First Name','lastname'=>'Last Name','age'=>'Age'); // list of permissible sort choices $sort_bys = array('asc','desc'); // list of permissible order by choices $limit = 3; // No of records to be shown per page. // condition inputs/set default values $start = (isset($_GET['start'])) ? (int)$_GET['start'] : 0; // default to starting row 0 if not specified $sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'firstname'; // default to firstname if not specified $sort_by = (isset($_GET['sort_by'])) ? $_GET['sort_by'] : 'asc'; // default to asc if not specified // validate sort input (used as a keyword in query statement) if(!array_key_exists($sort,$sorts)){ $sort = 'firstname'; // default to firstname } // validate sort_by input (used as a keyword in query statement) if(!in_array($sort_by,$sort_bys)){ $sort_by = 'asc'; // default to asc } $eu = $start; $this1 = $eu + $limit; $back = $eu - $limit; $next = $eu + $limit; // get opposite sort_by value for producing toggle links in the table heading (only) if($sort_by == 'asc'){ $sort_order = 'desc'; } else { $sort_order = 'asc'; } /////////////// WE have to find out the number of records in our table. We will use this to break the pages/////// $query="SELECT COUNT(*) FROM $table"; $result=mysql_query($query); //echo $query, mysql_error(); list($nume) = mysql_fetch_row($result); /////// The variable nume above will store the total number of records in the table//// /////////// Now let us print the table headers //////////////// $bgcolor="#f1f1f1"; echo "<table border='1'>" ; echo "<tr> <th>ID</th>"; // dynamically produce choices/columns foreach($sorts as $key=>$value){ echo "<th><a href='?sort=$key&sort_by=$sort_order'>$value</a></th>"; } echo "</tr>"; ////////////// Now let us start executing the query with variables $eu and $limit set at the top of the page/////////// //$query="SELECT * FROM $table ORDER BY $sort $sort_by limit $eu, $limit"; $query="SELECT * FROM $table where firstname like '%" . $_POST['search'] . "%' or lastname like '%" . $_POST['search'] . "%' or age like '%" . $_POST['search'] . "%' ORDER BY $sort $sort_by limit $eu, $limit"; $result=mysql_query($query); //echo $query, mysql_error(); $count = (isset($eu) && $eu > 0) ? $eu+1 : 1; //////////////// Now we will display the returned records in side the rows of the table///////// while($rows = mysql_fetch_array($result)){ // toggle bgcolor if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';} else{$bgcolor='#f1f1f1';} echo "<tr >"; echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>"; echo $count++; echo "</font></td>"; echo "<td>$rows[firstname]</td>"; echo "<td>$rows[lastname]</td>"; echo "<td>$rows[age]</td>"; echo "</tr>"; } echo "</table>"; ////////////////////////////// End of displaying the table with records //////////////////////// /////////////////////////////// if($nume > $limit ){ // Let us display bottom links if sufficient records are there for paging /////////////// Start the bottom links with Prev and next link with page numbers ///////////////// echo "<table align = 'center' width='50%'><tr><td align='left' width='30%'>"; //// if our variable $back is equal to 0 or more then only we will display the link to move back //////// if($back >=0){ $_GET['start'] = $back; // only modify the 'start' value, all others left as is $q = http_build_query($_GET,'','&'); print "<a href='?$q'><font face='Verdana' size='2'>PREV</font></a>"; } //////////////// Let us display the page links at center. We will not display the current page as a link /////////// echo "</td><td align=center width='30%'>"; $i=0; $l=1; for($i=0;$i < $nume;$i=$i+$limit){ if($i <> $eu){ $_GET['start'] = $i; // only modify the 'start' value, all others left as is $q = http_build_query($_GET,'','&'); echo " <a href='?$q'><font face='Verdana' size='2'>$l</font></a> "; } else { echo "<font face='Verdana' size='4' color=red>$l</font>";} /// Current page is not displayed as link and given font color red $l=$l+1; } echo "</td><td align='right' width='30%'>"; ///////////// If we are not in the last page then Next link will be displayed. Here we check that ///// if($this1 < $nume){ $_GET['start'] = $next; // only modify the 'start' value, all others left as is $q = http_build_query($_GET,'','&'); print "<a href='?$q'><font face='Verdana' size='2'>NEXT</font></a>"; } echo "</td></tr></table>"; }// end of if checking sufficient records are there to display bottom navigational link. include "menu.php"; ?>
- 6 replies
-
- search
- pagination
-
(and 1 more)
Tagged with:
-
I'm trying to add pagination but failing badly Here's my code: $query = "SELECT COUNT(*) FROM searchacts"; $pages = new Paginator; $pages->items_total = $num_rows[0]; $pages->mid_range = 9; $pages->paginate(); echo $pages->display_pages(); //### Initialize variables $pages = isset($_GET['page']) ? $_GET['page'] : FALSE ; $category = isset($_GET['categories']) ? $_GET['categories'] : FALSE ; $sort = isset($_GET['sort']) ? $_GET['sort'] : FALSE ; $upto = isset($_GET['upto']) ? $_GET['upto'] : FALSE ; //### Create the URL parameters $urlParameters = '?categories='. $category .'&upto='. $upto .'&sort='. $sort .'&page='. $pages .''; //### Start the query variable $query = 'SELECT * FROM `searchacts` $pages->limit'; //### Initialize query options $queryOptions = array(); //### Now check each of the sorting values //### Check which category we are searching in if($category == 'PopandRock') { $queryOptions[] = "`category` = 'Pop and Rock'"; } else if($category == 'SoulFunkDiscoMowtown') { $queryOptions[] = "`category` = 'Soul, Funk, Disco and Motown'"; } //### Check what value upto we are returning if($upto == '100') { $queryOptions[] = "`price` <= 100"; } else if($upto == '200') { $queryOptions[] = "`price` <= 200"; } else if($upto == '300') { $queryOptions[] = "`price` <= 300"; } //### Create final query $queryWhere = isset($queryOptions[0]) ? ' WHERE '.implode(' AND ', $queryOptions) : '' ; $finalQuery = $query . $queryWhere; //### Add the order by to the end of the query if($sort == 'PriceLow') { $finalQuery .= ' ORDER BY `price` ASC'; } else if($sort == 'PriceHigh') { $finalQuery .= ' ORDER BY `price` DESC'; } //echo $finalQuery; //echo '<br>'.$urlParameters; $result = mysql_query($finalQuery); $num = mysql_num_rows($result); and i've been trying to use this script/tutorial: http://net.tutsplus.com/tutorials/php/how-to-paginate-data-with-php/ so i've included the paginator.class.php, the $pages->limit on my select and tried to implement it into my url parameters Any Ideas? Thanks
-
Hi Everyone, I am having a problem here. I am trying to send mail to a list of selected people. So I have used check-boxes for multiple select. The list comes from the database. I have used pagination with a limit of 10 records in a page. Now I select say 3 records in page 1 , go to the next page and select 2 from there. I want the mail to be sent to all 5 people when I click submit. But the mail is sent only to the values selected on the page in which I click 'send' , which is the submit button. Is there any way to retain the selected checkbox values ? Thanks in advance, Anshu
-
Hey Guys, I'm using a script within my wordpress site, but the author is not responding to any questions so I'm hoping someone here could help me out... One gallery I uploaded has 280 images, When viewing the gallery I see the first 20 images and just a simple “More Images” and “Previous Images” links. Is there a way to set it so it displays something like: Images 1-20 of 280 displayed. Results: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Next >> function display_galleries() { //allow plugins to overwrite output $output = apply_filters('ims_before_galleries', '', $this->gallery_tags, $this); if ('' != $output) return $output; extract($this->gallery_tags); global $post, $wp_query; $attach = ( (!empty($this->opts['attchlink']) && empty($this->meta['_to_attach'][0])) || !empty($this->meta['_to_attach'][0])); if (!empty($post->post_excerpt) && $this->in_array($this->imspage, array('photos', 'slideshow'))) $output = '<div class="ims-excerpt">' . $post->post_excerpt . '</div>'; $output .= "<{$gallerytag} id='ims-gallery-" . $this->galid . "' class='ims-gallery' itemscope itemtype='http://schema.org/ImageGallery'>"; foreach ($this->attachments as $image) { $title = get_the_title($image->ID); if (!empty($image->post_parent)) { $title = get_the_title($image->post_parent); $link = get_permalink($image->post_parent); } elseif ($attach) { $link = get_permalink($image->ID); } else { $image->meta['class'] = 'photo ims-colorbox'; $link = $this->get_image_url($image->ID); } $image->meta += array( 'link' => $link, 'alt' => $title, 'caption' => $title, 'title' => $title); $output .= $this->image_tag( $image->ID, $image->meta ); } $output .= "</{$gallerytag}>"; $wp_query->is_single = false; $output .= '<div class="ims-navigation">'; $output .= '<div class="nav-previous">' . get_previous_posts_link(__('<span class="meta-nav">←</span> Previous images', 'ims')) . '</div>'; $output .= '<div class="nav-next">' . get_next_posts_link(__('More images <span class="meta-nav">→</span>', 'ims')) . '</div>'; $output .= '</div><div class="ims-cl"></div>'; $wp_query->post_count = 1; $wp_query->is_single = true; $this->visited_gallery(); //register visit return $output; } I believe that is the code that actually writes the pagination area, I'm happy to post any other code if needed. Can anyone help me out please?
-
<?php session_start(); $per_page = 10; $query = mysql_query("SELECT * FROM 'bio'"); echo $pages = mysql_result($pages_query, 0); if ($_SESSION ['username']) echo "<right>Welcome, ".$_SESSION['username']."!<br><a href='logout.php'>Log out</a><br><a href='bio.php'>Post an Ad!</a></right>"; else die("You must be logged in!"); $connect = mysql_connect("localhost","root","4shizzle"); //connect to server mysql_select_db("textbooks"); //query the database $query = mysql_query("SELECT * FROM bio"); echo "<table border=1 cellpadding=10> <tr> <th>Date</th> <th>Class</th> <th>Book</th> <th>Price</th> <th>Email</th> </tr>"; while($rows = mysql_fetch_array($query)): $class = $rows['class']; $title = $rows['title']; $email = $rows['email']; $price = $rows['price']; $date = $rows['date']; $newDate = date("M-d", strtotime($date)); echo "<tr>"; echo "<td>" . $newDate . "</td>"; echo "<td>" . $class . "</td>"; echo "<td>" . $title . "</td>"; echo "<td>" . $price . "</td>"; echo "<td>". $email . "</td>"; echo "</tr>"; endwhile; ?>
-
Hello, I have a file where I want to make the pagination visible right after the ending of the post. Right now it is showing after all modules/widgets but I want it above the facebook like so that the pagination is visible right away. I tried a various modification with that code but couldn't find the right solution, so I would like your help. The code responsible for that is wp_link_pages (line 38) that is in the code listed below. The preview of that is here: http://www.sedziapilkarski.pl/sedziowie-3/letni-turniej-pilkarski-sedziow/2252 <?php get_header(); ?> <div id="container"> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div id="post-<?php the_ID(); ?>" <?php post_class('entry'); ?>> <h1 class="entry_title"><?php the_title(); ?></h1> <div class="metasingle"> <span class="postDate"><?php echo get_the_date('') ?> | </span> <span class="postCategory"><?php _e('Filed under','linepress'); ?>: <?php the_category(','); echo get_the_term_list( $post->ID, 'gallery-cat', ': ', ' ', '' ); ?> | </span> <span class="postAuthor"><?php _e('Posted by','linepress'); ?>: <?php the_author_posts_link(); ?></span> </div><!-- /metas --> <?php // Theme innerpage slider gab_innerslider(); // Display edit post link to site admin edit_post_link(__('Edit This Post','linepress'),'<p>','</p>'); // If there is a video, display it gab_media(array( 'imgtag' => 1, 'link' => 1, 'name' => 'gabfire', 'enable_video' => 1, 'video_id' => 'post', 'catch_image' => 0, 'enable_thumb' => 0, 'media_width' => '623', 'media_height' => '360', 'thumb_align' => 'alignnone', 'enable_default' => 0, )); // Display content the_content(); // Display pagination wp_link_pages(array('before' => __('<strong>Strony:</strong> ', 'arras'), 'after' => '', 'next_or_number' => 'number')); // make sure any floated content gets cleared echo '<div class="clear"></div>'; //If there is a widget, display it gab_dynamic_sidebar('PostWidget'); // Display edit post link to site admin edit_post_link(__('Edit This Post','linepress'),'<p>','</p>'); ?> <?php if(of_get_option('of_ln_entry_meta') == 1) { ?> <div id="entryMeta"> <?php echo get_avatar( get_the_author_email(), '27' ); ?> <?php _e('Posted by','linepress'); ?> <?php the_author_posts_link(); ?> <?php /* This is commented, because it requires a little adjusting sometimes. You'll need to download this plugin, and follow the instructions: http://binarybonsai.com/archives/2004/08/17/time-since-plugin/ */ /* $entry_datetime = abs(strtotime($post->post_date) - (60*120)); echo time_since($entry_datetime); echo ' ago'; */ ?> <?php _e('on','linepress'); ?> <?php echo get_the_date(''); ?>. <?php _e('Filed under','linepress'); ?> <?php the_category(', ') ?>. <?php _e('You can follow any responses to this entry through the','linepress'); ?> <?php comments_rss_link('RSS 2.0'); ?>. <?php if (('open' == $post-> comment_status) && ('open' == $post->ping_status)) { // Both Comments and Pings are open ?> <?php _e('You can leave a response or trackback to this entry','linepress'); ?> <?php } elseif (!('open' == $post-> comment_status) && ('open' == $post->ping_status)) { // Only Pings are Open ?> <?php _e('Responses are currently closed, but you can trackback from your own site.','linepress'); ?> <?php } elseif (('open' == $post-> comment_status) && !('open' == $post->ping_status)) { // Comments are open, Pings are not ?> <?php _e('You can skip to the end and leave a response. Pinging is currently not allowed.','linepress'); ?> <?php } elseif (!('open' == $post-> comment_status) && !('open' == $post->ping_status)) { // Neither Comments, nor Pings are open ?> <?php _e('Both comments and pings are currently closed.','linepress'); ?> <?php } ?> <div class="clear"></div> </div> <?php } ?> </div><!-- /post --> <?php endwhile; else : endif; ?> <?php if ( of_get_option('of_ln_singlepage') <> "" ) { ?> <div class="single_ad"> <?php if(file_exists(TEMPLATEPATH . '/ads/single_468x60/'.current_catID().'.php') && (is_single() || is_category())) { include_once(TEMPLATEPATH . '/ads/single_468x60/'.current_catID().'.php'); } else { include_once(TEMPLATEPATH . '/ads/single_468x60.php'); } ?> </div> <?php } ?> <?php comments_template(); ?> </div><!-- /container --> <div id="sidebar"> <?php get_sidebar(); ?> </div><!-- End of sidebar --> <div class="clear"></div> <?php get_footer(); ?>
-
I would like to develop a system that makes remote reading of the result of some search sites. These results are paginated and many sites use ajax to load pages. How can I accomplish this system with php? example of a site search page result: http://busca.submarino.com.br/busca.php?q=celular&sessao=4b712361eee996720660b5d6bde5dfc1f22066c9&idbusca=c9aeb969a4e7fb45bbbf152c85f1234cd768f5e7 As you can see at the bottom of the page, there is some javascript attached to the pagination link. Can anyone help with some idea? Thanks