PHP Pagination Div Showing Error Result - php

Hello i have a quick question.
This is the code
<div class="beta-pagination text-center">
<?php
if($page > 1) {
echo '<i class="fa fa-chevron-left"></i>' . "\n";
if($page > 2) {
echo '...';
}
echo ''. ($page - 1) .'';
} else {
echo '<i class="fa fa-chevron-left"></i>' . "\n";
}
?>
<?php echo $page; ?>
<?php echo ($page + 1); ?>
...
<i class="fa fa-chevron-right"></i>
</div>
I use this pagination div on one of my shopping website, and is working great if use this url "www.domain. com/search?q=shoes" website is displaying all of my products from database.
And when i press next page goes to "www.domain. com/search.php?page=2&q=shoes" and is perfect.
But the problem is when i want to display second page of products based on merchant.
For example if i go on www.domain .com/search/search.php?brand=503 it display the results alright, but when press next page button it sends me to www.domain .com/search.php?page=2&q= and i need to go on www.domain .com/search.php?page=2&brand=503
Can someone please help me out with what should i add to my div code? a paste with the new code will be great! Thanks.

You lose 'brand' when making url for href. For common case write such code to save input get string
$query = $_GET;
if(isset($query['page'])) unset($query['page']);
$query = http_build_query($query);
and replace .'&q='. by.'&'.$query.

Related

Access a special div, generated by a while loop

I'll try to be clear. My problem is that i'm using php to get data from mysql. The table has more than one record. To show table records i'm using a while loop that as a condition has mysqli_fetch_array(). The records from the table must be shown in an echo(because i want to show them as html on the page), but every div generated from the while loop has a link to send me to another page, and if the client clicks on that link it will get the current divs information(after the table in database has more than one record the informations will be different) to be shown at the next page. Hope you understood it. Thanks in advance!
while($rows1 = mysqli_fetch_array($query1,MYSQLI_ASSOC))
{
echo "<div class=\"row\">
<div class=\"col-md-6\">
<div class=\"thumb\">
<figure>
<img src=\"images/extra-images/room-grid1.jpg\" alt=\"\"/>
<figcaption>
<a rel=\"prettyPhoto[gallery2]\" href=\"images/extra-images/room-grid1.jpg\">
<i class=\"fa fa-search\"></i>
</a>
</figcaption>
</figure>
</div>
</div>
<div class=\"col-md-6\">
<div class=\"text\">
<h4>".$rows1['Dh_lloji']."</h4>
<p>".$rows1['Dh_Pershkrimi']."</p>
<ul class=\"room-grid-meta\">
<li>Max: ".$rows1['Dh_Kapaciteti']."</li>
<li>Size: ".$rows1['Dh_madhesia']."</li>
<li>Floor: ".$rows1['Dh_Kati']."</li>
</ul>
<div class=\"retail room-grid-retail\">
<span>
<sup>$</sup>
".$rows1['Dh_cmimi']."
<sub>night</sub>
</span>";
if(isset($_SESSION['Emri_Mbiemri']) != '')
{
echo "<a class=\"btn-3\" href=\"payment.php\">Book now</a>";
}else{
$error = "You must be logged in to book!";
}
echo "<br>".$error."</div>
<div id=\"price_room\">".$rows1['Dh_cmimi']."</div>
</div>
</div>
</div>";
$count++;
}
Looks like you need at least your custom counter, that will be increment inside cycle, and set div's id based on this counter plus use it in generated link
I made a solution for my problem and i wanted to share it with you guys. I gave a $count to the links defining every link the while loop generates...
<a class=\"btn-3\" href=\"payment.php?id=$count\">Book now</a>
After that i used a multidimensional array to store the current divs variable(in my case rooms price, the count, and the id) of the room from database...
$room_prices[$count][0] = $rows1['Dh_cmimi'];
$room_prices[$count][1] = $count;
$room_prices[$count][2] = $rows1['ID_Dhoma'];
After the client click a specific link he will get the id so i can make a search at my multidimensional array for the price and the id of that room..
for($i = 0; $i < $count; $i++)
{
if($_GET['id'] == $room_prices[$i][1]){
$sess_room_price = $room_prices[$i][0];
$sess_room_id = $room_prices[$i][2];
}
}
After i get these i store them at the global session variables to use them at the other page...
$_SESSION['Rooms_Price'] = $sess_room_price;
$_SESSION['Rooms_ID'] = $sess_room_id;
So this did the work for me... Hope this helps others.

WordPress next and previous link modification

Basically, my Wordpress site has about 50,000 unique posts, I want to incorporate asdfly to the next/previous post link buttons. I want to insert asdfly/527275432/ before the next/previous url, so it would look like this..
asdfly/527274352/www.google.com/previous
(Previous Post Title)
asdfly/527274352/www.google.com/next
(Next Post Title)
Is there any possible way to do this? I tried with the template but I couldn't figure it out.. Someone had managed to help me before but the same code doesn't work on the new site I'm working with, this is a different theme so maybe that's why. Here is what my current next and previous post buttons are/look like:
<div class="right-side">
<?php
if( $prev_link != NULL )
echo $prev_link . "<i title='Last Episode' class='playerleft tooltips fa fa-angle-double-left'> </i></a>";?>
<a class="tooltips" title='View all <?php echo $name; ?> Episodes' href='<?php echo $series_link; ?>'><i class="allepisodes fa fa-sort-amount-asc"></i></a>
<?php
if( $next_link != NULL )
echo $next_link . "<i title='Next Episode'class='playerright tooltips fa fa-angle-double-right'> </i></a>"; ?>
</div> <!-- End of right side -->
This is the previous code someone has gotten for me, however it doesn't work on this website:
function modify_prev_link( $link ) {
$link = str_replace( "href=\"http://", "href=\"http://asdf.ly/527274352/", $link );
return $link;
}
add_filter( 'previous_post_link', 'modify_prev_link' );
function modify_next_link( $link ) {
$link = str_replace( "href=\"http://", "href=\"http://asdf.ly/527274352/", $link );
return $link;
}
add_filter( 'next_post_link', 'modify_next_link' );
An example of what this would look like on the page:
http://animewolf.tv/anime/yama-no-susume-2nd-season-episode-21-subbed/
If you refer to the buttons on the right side below the video player, I want to modify them so that the adfly code will come before the url of the next episode.
I've been going crazy trying to find an answer for this, if anyone knows of one I will tip you $5 paypal, just leave me your pp after I've confirmed it's worked :) just a little side note to show my appreciation.
Thanks
Not sure if this will work, but tested on wordpress with different template.
I tried with your button link which don't work on my templates.
Changed code for button link (most likely on single.php file)
<?php next_post_link( '%link', "<i title='Last Episode' class='playerleft tooltips fa fa-angle-double-left'> </i>", TRUE ); ?>
<a class="tooltips" title='View all <?php echo $name; ?> Episodes' href='<?php echo $series_link; ?>'><i class="allepisodes fa fa-sort-amount-asc"></i></a>
<?php previous_post_link( '%link', "<i title='Next Episode'class='playerright tooltips fa fa-angle-double-right'> </i></a>", TRUE ); ?>
edit on your function.php file (changing function) working fine.
Hope it help.
:)

How to use bootstrap pagination with php

I am a working with php and mysql and I managed to do pagination following this tutorial:
http://www.phpfreaks.com/tutorial/basic-pagination
Here is "mywebpage" (on work): http://ada.uprrp.edu/~ehazim/hpcf_proj/miejemplo.php
But Now, I want to make it "pretty" using bootstrap Pagination:http://getbootstrap.com/components/#pagination
I am using _GET['current_page'] to get the page where I am. The problem is that I dont know how to change the echo's to echo the pagination from bootstrap... Yes, it may be stupid, but It is my first time with php and I am like 2 hours just trying to do this. Can someone help me? Below is the code that I have, following the tutorial of php freaks (which I understand, except for some echos with toomany quotes :/ ):
<div class="pagination">
<ul>
<?php
/****** build the pagination links ******/
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
# TRYING TO CHANGE HERE AND IN OTHER ECHOS
#echo "<li>«</li>";
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
#echo " <li><a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} // end if
# range of num links to show
$range = 3;
# loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo " [<b>$x</b>] ";
// if not current page...
}
else {
// make it a link
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
// echo forward link for lastpage
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
} // end if
# end build pagination links
?>
</ul>
</div>
To get you started, Bootstrap pagination works on a ul of class = pagination with the page links as list items.
Towards the start of your php code add the pagination class to the ul (not the div)
<ul class="pagination">
Then wherever you echo a page link, wrap it with li tags, e.g.
echo " <li><a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> </li>";
EDIT
You also want to tweak the HTML for the current page by changing
echo " [<b>$x</b>] ";
to
echo " <li>$x</li> ";
Edit
If you want to center your pagination bar, Bootstrap 3 has a the text-center class which you can use. See http://jsfiddle.net/panchroma/8RHzw/
Change the first line of your php to
<div class="text-center">
With Bootstrap 2, use
<div style="text-align:center;">
Hope this helps!
Further to David Taiaroa's answer above, for the active button state you need to add the class="active" and A tags.
echo " <li>$x</li> ";
..becomes..
echo " <li class=\"active\"><a>$x</a></li> ";

Next & previous links: Not showing a link if there isn't a next page

I've followed the documentation here (at the bottom) to create next and back buttons at the bottom of my page.
It seems to work fine until I get to the last page where the link just redirects me back to the first page. Is there a way to say if there isn't a next page to not show the link? I assumed thats what the if statement was supposed to do!!
<?php
$pagelist = get_pages('sort_column=menu_order&sort_order=asc');
$pages = array();
foreach ($pagelist as $page) {
$pages[] += $page->ID;
}
$current = array_search(get_the_ID(), $pages);
$prevID = $pages[$current-1];
$nextID = $pages[$current+1];
?>
<?php if (!empty($prevID)) { ?>
<a class="back" href="<?php echo get_permalink($prevID); ?>">BACK</a>
<?php } ?>
<?php if (!empty($nextID)) { ?>
<a class="next" href="<?php echo get_permalink($nextID); ?>">NEXT</a>
<?php } ?>
p.s Please don't move my question to the Wordpress Stack - that seems to be dying a bit of a death and doesn't get many responses!
My Pages are setup like this:
Parent page
Sub page 1
Sub page 2
Sub page 3
I've created a link on the parent page to goto the first subpage. Then on the subpage template I've got the code above. I just want the next link to appear on each page then when it gets to page 3 it shouldn't show the next link.
If you are saying that this is effectively looping around then $nextID must never be empty, which would be why the link was always displayed.
You could set a $firstID, ie
$firstID = pages[0];
and then check;
if ($firstID != $nextID ) {
// Display link
}

pagination bold on page click

I'm trying to get the link to turn bold when i click on the page but the following code is failing me. can somebody point out what i'm doing wrong?
for($i=1;$i<=$pages;$i++)
{
echo ($i == #$page) ? '<strong>'.$i.' </strong> ': ''.$i.' ';
}

Categories