Advertisement

03.04.2008 at 01:56AM PST, ID: 23212080
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

Php mysql paging problem

Asked by Toube in PHP and Databases, PHP Scripting Language

Tags:

Hello,

I recently asked a similar question but I didn't get any answers so here it goes again.

I have paging class that handles the paging for my database queries and all is working well except for when I try do handle the paging through a search.. then the paging brakes down and doesn't work any more.

the search is not passed to the next page and so on, how can I fix this?

Regards,

-TStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
// This is used for getting the reult in to the pager class
 
   class Pager
   {
       function getPagerData($numHits, $limit, $page)
       {
           $numHits  = (int) $numHits;
           $limit    = max((int) $limit, 1);
           $page     = (int) $page;
           $numPages = ceil($numHits / $limit);
 
           $page = max($page, 1);
           $page = min($page, $numPages);
 
           $offset = ($page - 1) * $limit;
 
           $ret = new stdClass;
 
           $ret->offset   = $offset;
           $ret->limit    = $limit;
           $ret->numPages = $numPages;
           $ret->page     = $page;
 
           return $ret;
       }
   }
 
$pageid = $_GET['id'];
$search = $_POST['search'];
$page = $_GET['main_page'];
require ('paging_function.php'); // get pager function
 
//Search query for the messages.
$sqlquery = "SELECT p.ID as postid, p.topicid, DATE_FORMAT(p.timestamp, '%d.%m.%Y %H:%i') AS insertdate,
DATE_FORMAT(p.timestamp, '%d.%m.%Y') AS time, DATE_FORMAT(p.timestamp,'%H:%i') AS minutes, p.timestamp as sent, p.post as post, DATE_FORMAT(t.topictime, '%d.%m.%Y %H:%i') AS topict, t.topicname as topicname, t.userlevel_topic as userlevel, t.ID as topicid, u.username as username, (SELECT count(*) FROM posts WHERE posts.topicid=t.id) as count,(select count(ID) as num from posts where topicID=t.id and ID <p.id) as msgbefore, u.users_id as usersid, c.lastread as userlastread FROM users u, posts p, topics t LEFT OUTER JOIN forum_read c ON (c.theader_=t.id AND c.user_ = '$userid') WHERE p.topicid=t.ID and t.deleted ='0' AND u.users_id = p.user_ and u.users_id=t.user_ and MATCH(p.post) AGAINST('%$search%' IN BOOLEAN MODE) group by postid order by p.timestamp desc";
 
 
$result2 = mysql_query($sqlquery);
 
$total = mysql_num_rows($result2);
//$amount1 = mysql_result($useramount, 0, 0);
$limit = 10;
$pager  = Pager::getPagerData($total, $limit, $page);
$offset = $pager->offset;
$limit  = $pager->limit;
$page   = $pager->page;
 
$numpages = $pager->numPages;
 
if (($page != $_GET['main_page']) && ($pager->numPages > 1))
{
    $pager  = Pager::getPagerData($total, $limit, $pager->numPages);
    $offset = $pager->offset;
    $page   = $pager->page;
}
 
//call the pager function:
page_count_search($total, $page, $limit, $numpages, $offset, $pager, $pageid);
 
// paging
 
function page_count_search($total, $page, $limit, $numpages, $offset, $pager, $pageid)
{
 
if ($total >= 20)
{
echo "<div class=\"member_links\" style=\"margin-bottom: 3px; font-size: 9px;\">";
 
if ($page == 1)
    echo "<img style=\"border: none;\" src=\"../images/red_arrow_back.gif\" alt=\"Previous page\"/>";
 
    else
    echo "<a href=\"index.php?id=$pageid&amp;main_page=" . ($page - 1) . "\"><img style=\"border: none;\" src=\"../images/red_arrow_back.gif\" alt=\"edellinen sivu\" title=\"edellinen sivu\" /></a>";
$ingap = false;
for ($i = 1; $i <= $numpages; $i++)
{
      if ($i <= 3 || $i > ($numpages -3) || abs($page - $i) < 2)
      {
            $ingap = false;
            echo "  ";
            if ($i == $page)
            {
                  echo "<span style=\"font-weight: bold; color: #000000; background-color: #e4900d; padding-left: 2px; padding-right: 2px;\">$i</span>";
            }
            else
            {
                  echo "<a href=\"index.php?id=$pageid&amp;main_page=$i\">$i</a>";
            }
      }
      else if (!$ingap)
      {
            $ingap = true;
            echo "  ... ";
      }
}
echo "  ";
    if ($page == $pager->numPages)
    echo "<img style=\"border: none;\" src=\"../images/red_arrow_front.gif\" alt=\"Next page\" />";
 
    else
    echo "<a href=\"index.php?id=$pageid&amp;main_page=" . ($page + 1) . "\"><img style=\"border: none;\" src=\"../images/red_arrow_front.gif\" alt=\"seuraava sivu\" title=\"seuraava sivu\" /></a>";
    echo "</div>";
    }
   else
   {
        echo "";
   }
 
}
 
?>
[+][-]03.04.2008 at 02:53AM PST, ID: 21039782

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP and Databases, PHP Scripting Language
Tags: Php mysql
Sign Up Now!
Solution Provided By: MatthewP
Participating Experts: 1
Solution Grade: A
 
 
[+][-]03.04.2008 at 03:03AM PST, ID: 21039828

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628