Page 1 of 1

letter pagination does not work

Posted: Wed Nov 25, 2009 4:38 pm
by dgnzcn
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\">&laquo;</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\">&raquo;</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>&nbsp;¦&nbsp;";
}
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>";
?>

Re: letter pagination does not work

Posted: Thu Nov 26, 2009 3:56 am
by sergio-pro
hi

Remove dots in query:

Code: Select all

 
"SELECT * FROM `urunler` WHERE `ad` LIKE '.$alphabet.%' ORDER BY `ad` DESC"
=>
"SELECT * FROM `urunler` WHERE `ad` LIKE '$alphabet%' ORDER BY `ad` DESC"
 
and next time format your code using

Code: Select all

[/code ] bb tag please.

Re: letter pagination does not work

Posted: Fri Nov 27, 2009 10:04 am
by dgnzcn
thanks but not work.