pagination bold on page click - php

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.' ';
}

Related

PHP Pagination Div Showing Error Result

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.

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> ";

not to show previous link at the start page and next link at the last page?

I have to links Next and Previous in Pagination. What I should do so that 'previous' link should hide when I was on the first page and the 'next' link should hide when I was on the last page?
my code for next and previous links is:
echo '<a href="'.$_SERVER['PHP_SELF'].'?page='
.($page-1).'&date1='.$_REQUEST["date1"].'&date2='.$_REQUEST["date2"].'">Previous</a>';
echo '<a href="'.$_SERVER['PHP_SELF'].'?page='
.($page+1).'&date1='.$_REQUEST["date1"].'&date2='.$_REQUEST["date2"].'">Next</a>';
It wont work well the way your doing it right now, unless you have the specific number of pages.
If you have the total number of pages, you can do this
if( $page > 1 ) {
echo '<a href="'.$_SERVER['PHP_SELF'].'?page='
.($page-1).'&date1='.$_REQUEST["date1"].'&date2='.$_REQUEST["date2"].'">Previous</a>';
}
if( $page < $totalPages ) {
echo '<a href="'.$_SERVER['PHP_SELF'].'?page='
.($page+1).'&date1='.$_REQUEST["date1"].'&date2='.$_REQUEST["date2"].'">Next</a>';
}

How to echo an output in a specific div

I have a page full of products and when the page reloads after the add to cart button has been clicked i want to display a check mark next to the product that was added.
Using the rows and columns count i have assigned each product it's own class, for example
<div class = "location12">
I passed the location via post when the add to cart button is pressed so i can tell which div the button press was from and i can then use that data as an identifier.
I can get the page to scroll back to this position by referencing the div, but i'm struggling to get the image to only display on that one product. It will display on that product and then every product after it because it echoes on every time it loops after the first output.
Already added to the individual product page, but they want the same function as here: http://confettibox.ch/1-NEWSTORE/index.php?main_page=product_info&cPath=576_578&products_id=1265&language=en
on this page here:
http://confettibox.ch/1-NEWSTORE/index.php?main_page=index&cPath=4_586
Add to cart button submit is coded here, and you can see where i added the hidden field to pass the id of the div
$lc_button= '<div class="back">' . zen_draw_form_prod_list('cart_quantity', preg_replace($pattern, $replacement, $string), 'post', 'enctype="multipart/form-data"') . '</div><div class="back qty_bg"><input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($listing->fields['products_id'])) . '" maxlength="6" size="4" /><br />' . zen_draw_hidden_field('products_id', $listing->fields['products_id']) . zen_draw_hidden_field('div_id', $colcount.$rows) . '</div><div class="forward">' . zen_image_submit('button_add.jpg', BUTTON_IN_CART_ALT) . '</form></div><br class="clearBoth">';
I added the $_POST result to a session var here:
$_SESSION['location'] = (int)$_POST['div_id'];
And then used:
if ($messageStack->size('listing') > 0 && $_SESSION['location'] == $colcount.$rows) {
so that the messageStack output (success checkmark) would only display for that one product... except it displays for everything after it too :|
Products are output using this code:
if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns') {
$lc_text = implode('<br />', $product_contents);
$list_box_contents[$rows][$column] = array('params' => 'class="centerBoxContentsProducts centeredContent back featured'. $column .'"' . ' ' . 'style="width:235px;"',
'text' => $lc_text = '
<div class="prod_table">
<div class="prod_image">' . zen_image(DIR_WS_IMAGES . $listing->fields['products_image'], $listing->fields['products_name'], IMAGE_PRODUCT_LISTING_WIDTH, IMAGE_PRODUCT_LISTING_HEIGHT, 'class="listingProductImage"') . '</div>
<div class="prod_name">' . $listing->fields['products_name'] . '</div>
<div class="prod_price back">'. zen_get_products_display_price($listing->fields['products_id']) .'</div>
<div class = "location'. $colcount.$rows .'">'.$success.' </div>
<div class="prod_content forward">'. $the_button .'</div>
</div>
');
$column ++;
$colcount=$column;
if ($column >= PRODUCT_LISTING_COLUMNS_PER_ROW) {
$column = 0;
$rows ++;
}
}
// End of Code fragment for Column Layout (Grid Layout) option in add on module
$listing->MoveNext();
$success is where i want the check to be output.
How can i echo the success message to only 'location12' ?
Is it even possible?
You haven't posted much code but I'll try answering.
You can do it either with Javascript or PHP.
With Javascript/jQuery you can set the background image of any div you want:
$('.location12').css("background-image", "url(/myimage.jpg)");
With PHP you need to count your iterations and only echo the image on $index==12.
I do not know if you are using foreach, for, while or any other method.
Assuming it is a foreach loop you can do the following:
$index = 1;
foreach ($products as $product) {
if ($index == 12) {echo "<img src=''/>"}
$index++;
}
As you can see, the jQuery method is easier.
Hope this helps!

Simple HTML Dom Parse Tables

I want to parse the news from the website which is : http://www.bakirkoykhb.gov.tr/?module=bizden_haberler , what i'm facing is the website has many tables without classes and very complicated and so on as you can see if you check the source code of the page, i get the headings like those ones :
Japonya-Türkiye Tıp Derneği'den Ziyaret
Saglık-Sen Gen. Başk.Memiş'ten Ziyaret
Vali Mutlu’ dan Ziyaret
and so on with my code below. but i don't have any idea that how can i parse the links which are contained under "Devamını Oku".
$html = file_get_html('http://www.bakirkoykhb.gov.tr/?module=bizden_haberler');
$j = 0;
foreach($html->find('b') as $element2){
echo "
<h3 ><a target=\"_blank\" href=\"#somethingtohere\">". $element2->plaintext . "</a></h3>
";
$j++;
if($j > 5) break;
}
Hope you can help, thank you.
This should do for you
echo "<h3 ><a href='http://www.bakirkoykhb.gov.tr/".$html->find('a',$j+22)->href."'>". $element2->plaintext . "</a></h3>";

Categories