Jump to content

letter pagination does not work


dgnzcn

Recommended Posts

Hi all.

 

my letter pagination does not work. if I press any letter of my page, nothing happen.

 

where is wrong.

 

thanks.

 

<!--mysql-->

<?php

if(empty($_POST)) {

$harf = $_GET['harf'];

$harf .= "%";

$search = $harf;

$sdesc = "*";

$classquery = "";

} else {

$search = $_POST['search'];

$search = "%" . $search . "%";

$sdesc = "%" . $search . "%";

$sclass = $_POST['harf'];

$classquery = "AND 'harf' = CONVERT( _iso-8859-9 '" . $sclass . "' USING latin5 )";

}

mysql_connect("localhost", "adminpa", "Lw");

mysql_select_db("adminpaneli");

// If current page number, use it

// if not, set one!

$query = mysql_query("SELECT * FROM `urunler` WHERE `ad` LIKE '.$alphabet.%' ORDER BY `ad` DESC");

 

if(!isset($_GET['page'])){

$page = 1;

} else {

$page = $_GET['page'];

}

 

// Define the number of results per page

$max_results = 5;

 

// Figure out the limit for the query based

// on the current page number.

$from = (($page * $max_results) - $max_results);

 

// Perform mysql query on only the current page number's results

$result = mysql_query("SELECT * FROM urunler ORDER BY ad DESC LIMIT $from, $max_results")

or die(mysql_error());

 

//TO PRINT OUT THE DATA

echo "<table border='1'>";

echo "<tr> <th>ad</th></tr>";

// keeps getting the next row until there are no more to get

while($urunler = mysql_fetch_array( $result )) {

// Print out the contents of each row into a table

echo "<tr><td>";

echo $urunler['ad'];

echo "</td><td>";

}

 

echo "</table>";

//STOP PRINTING OUT THE DATA

 

// Figure out the total number of results in DB:

$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM urunler ORDER BY ad DESC"),0);

 

// Figure out the total number of pages. Always round up using ceil()

$total_pages = ceil($total_results / $max_results);

 

// Build Page Number Hyperlinks

echo "<p class=\"center\">Sayfa: ";

 

// Build Previous Link

if($page > 1){

$prev = ($page - 1);

echo "<a href=\"".$_SERVER['php_SELF']."?page=$prev\">«</a> ";

}

 

for($i = 1; $i <= $total_pages; $i++){

if(($page) == $i){

echo "$i ";

} else {

echo "<a href=\"".$_SERVER['php_SELF']."?page=$i &harf=$harf\">$i</a> ";

}

}

 

// Build Next Link

if($page < $total_pages){

$next = ($page + 1);

echo "<a href=\"".$_SERVER['php_SELF']."?page=$next\">»</a>";

}

echo "</p>";

 

mysql_close();

?>

<?php

 

$alphabet = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');

foreach ($alphabet as $harf) {

echo "<a href=\"?harf=" . $harf . "\">" . $harf . "</a> ¦ ";

}

echo "<a href=\"?\">Show All</a></p><br />

<form method=\"post\" action=\"?\">

<input type=\"text\" name=\"search\" /> <select name=\"class\">

<option>Select Category</option>

<option>---</option>

<option value=\"restaurant\">restaurant</option>

</select>

<input type=\"submit\" name=\"submit\" value=\"Search\" class=\"submit\" />

</form>";

?>

Link to comment
https://forums.phpfreaks.com/topic/182959-letter-pagination-does-not-work/
Share on other sites

I'm sorry.. I don't quite understand why you would want a alphabetical pagination, however, you'd probably want to do

 

$page = (ord(strtolower($_GET['harf'])) - ord('a'));

 

that will give you 0-25depending on the letter.. and you could use that in your query

 

SELECT .. FROM ... WHERE ... = ... LIMIT $page*5,($page*5)+5

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.