I need someone helps regarding pagination problem...i actually want to make my page limited to let say 50
so it will look like this
page1=0-50
page2=51-100
Then i want to sort let say based on the name of a person by giving <a href> and ORDER i can do the sort, but the problem occurs when i want to sort records on page 2, everything got messed up
Can anyone help me..below is the code:
<?php
$var2 =$_GET['title'] ;
$var3 =$_GET['field'] ;
$var4 =$_GET['country'] ;
$orderby = $_GET['orderby'];
if(empty($_GET['orderby'])){
$orderby="firstname";}
$sort=$_GET['sort'];
if(empty($_GET['sort'])){
$sort="DESC";}
if($sort=="DESC"){
$sort="ASC";}else
if($sort=="ASC"){
$sort="DESC";}
$trimmed2 = trim($var2); //trim whitespace from the stored variable
$trimmed3 = trim($var3);
$trimmed4 = trim($var4);
$table = "members";
$field_to_search2 = "title";
$field_to_search3 = "field";
$field_to_search4 = "country";
$query = "SELECT COUNT(*)FROM $table WHERE $field_to_search2 LIKE '%$trimmed2%'AND $field_to_search3 LIKE '%$trimmed3%' AND $field_to_search LIKE '%$trimmed%' AND $field_to_search4 LIKE '%$trimmed4%' ORDER BY $orderby $sort";
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrow = $r[0];
$rowsperpage = 100;
$totalpages = ceil($numrow / $rowsperpage);
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
$currentpage = (int) $_GET['currentpage'];
} else {
$currentpage = 1;
}
if ($currentpage > $totalpages) {
$currentpage = $totalpages;
}
if ($currentpage < 1) {
$currentpage = 1;
}
$offset = ($currentpage - 1) * $rowsperpage;
$query5 = "SELECT * FROM $table WHERE $field_to_search2 LIKE '%$trimmed2%'AND $field_to_search3 LIKE '%$trimmed3%' AND $field_to_search LIKE '%$trimmed%' AND $field_to_search4 LIKE '%$trimmed4%' AND $field_to_search5 LIKE '%$trimmed5%' ORDER BY $orderby $sort";
$result5 = mysql_query($query5);
$count5 = mysql_num_rows($result5);
$query = "SELECT * FROM $table WHERE $field_to_search2 LIKE '%$trimmed2%'AND $field_to_search3 LIKE '%$trimmed3%' AND $field_to_search4 LIKE '%$trimmed4%'ORDER BY $orderby $sort LIMIT $offset, $rowsperpage";
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
$count = mysql_num_rows($result);
$info = mysql_fetch_array($result);
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
$mypage=$_SERVER['PHP_SELF'];
if ($numrows == 0 )
{
echo "<center><font face=arial size=2><p>Search </font>"."<font face=arial size=2> returned zero results</font></p></center>";
}
if (empty($s))
{
$s=0;
}
// get results
$result = mysql_query($query) or die("Couldn't execute query");
if($numrows > 1 ){$return = "results";}
else{ $return = "result"; }
echo "<center><table><tr><td><a href=page.php?title=$var2&field=$varx3&q=$var&country=$var4&campus=$var5&orderby=firstname&sort=$sort&search2=Find class=sort>Name</a></td><td width = 70 bgcolor=brown><a href=page.php?title=$var2&field=$var3&country=$var4&orderby=gender&sort=$sort&search2=Find class=sort>gender</a></td></tr></table></center>";
$count = $s + 1 ;
while ($r= mysql_fetch_array($result))
{
$gender = $r["gender"];
$firstname1 = $r["firstname"];
$field = $r["field"];
$country = $r["country"];
$count++ ;
echo "<center><table><tr><td>$firstname</td><td>$gender</td><td>$country</td></tr></table>";
}
$range = 5;
echo"<center>";
if ($currentpage > 1) {
$var2 =$_GET['title'] ;
$var3 =$_GET['field'] ;
$var4 =$_GET['country'] ;
echo " <a href='{$_SERVER['PHP_SELF']}?title=$var2&field=$var3&country=$var4&search2=Find¤tpage=1'><font face=verdana size=2>First</font></a><font face=verdana size=2> |</font>";
$prevpage = $currentpage - 1;
echo " <a href='{$_SERVER['PHP_SELF']}?title=$var2&field=$var3&country=$var4&search2=Find¤tpage=$prevpage'><font face=verdana size=2>Previous</font></a><font face=verdana size=2> | </font>";
}
for ($x = ($currentpage - $range); $x < ($currentpage + $range); $x++) {
if (($x > 0) && ($x <= $totalpages)) {
if ($x == $currentpage) {
echo "<font face=verdana size=2> [<b>$x</b>] </font>";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?title=$var2&field=$var3&country=$var4&search2=Find+resume¤tpage=$x'><font face=verdana size=2>$x</font></a> ";
}
}
}
if ($currentpage < $totalpages) {
$nextpage = $currentpage + 1;
echo "<font face=verdana size=2>|</font> <a href='{$_SERVER['PHP_SELF']}?title=$var2&field=$var3&country=$var4&search2=Find¤tpage=$nextpage'><font face=verdana size=2>Next</font></a><font face=verdana size=2> | </font>";
echo "<a href='{$_SERVER['PHP_SELF']}?title=$var2&field=$var3&country=$var4search2=Find¤tpage=$totalpages'><font face=verdana size=2>Last</font></a>";
}
echo"</center>";
?>
Thanks
Help Optimizing code
Good Morning,I wrote a small import function for a website of mine and I know there has to be a better way to handle what I'm doing. I'm hoping someone can take my code and make it run a hair faster
I need help on this PHP code
Hi everybody, I made some kind of mistake while editing the code below. As you see, at the 3 row my news are repetition of raw 2. http://www.demirtepe.net/haber/index17.phpAs a matter of fact, I had
Simple Variable Question
Hi everyone.... again,I am really getting into php still. Learning more every day. I love it.But I have run into a problem I cannot solve.From what I understand, you can only "echo
problems with php variables in mysql query
i can't seem to get the following query to work. select $q1c from $vote_rate where id = $recent_record LIMIT 0,1 ;this method did not work eitherselect .$q1c. from .$vote_rare. where id =
upload image name with extension using php
hi frds..<input id="file1" type="file" name="file[]" >upload image show path like C:\Documents and Settings\My Documents\My Pictures\images0056.jpgi need
How to search for several parameters from objects in a database?
I have a database with lots of information about objects.Now I would like to search for 4 or 5 parameters at the same time (from a form) like this:I choose from a select-box one parameter and then
How to change www in url with a specified name
HiI'm trying to change the url http://www.sitename.com/apparels to something like belowhttp://apparels.sitename.com/apparels in PHP.If anybody can help me with the code for the same or provide links
how to get values from $_Post with onchange="form.submit();"?
Hi, I have a form that submit to itself with a file upload field and two other hidden field values.If I put a submit button on the page, all is working fine.I don't like the submit button as its
a multi dimensional array with for each
hi, I have been asked to write an array, I have Zone 2,3,4,5,6,7,8 each zone has 3 sections of weight, 0 = 70, 71 = 100, 101 = 150, each zone has an average number of say about 0.147 and a Base number
Any help with my email script?
I have an email script, I have not tested it, although someone tested it for me and said it worked fine. I started to make modifications to the code after using the basic structure. This is my HTML