pixeltrace Posted June 22, 2007 Share Posted June 22, 2007 guys, i need help, i have a display page with pagination and gets an error whenever i go to the other page (let say page2) i have 2 page first page is the search page, wherein i search an item and then goes to the second page which is the display page. on my display page, i have a search tool there also, and that one works fine and whenever i used it, i dont get the error on the pagination. below is the code for my first page <table width="562" border="0" cellspacing="2" cellpadding="3"> <tr> <td colspan="3" valign="top"><img src="images/spacer.gif" width="10" height="1" /></td> </tr> <tr> <td colspan="3" bgcolor="#999999" class="text2">Keyword Search </td> </tr> <tr> <td colspan="3" valign="top"><img src="images/spacer.gif" width="10" height="10" /></td> </tr> <form action="searchcnddate.php?id=2" method="post"><tr> <td width="83" align="right" valign="top" class="text6">keywords : </td> <td width="1" rowspan="4"> </td> <td width="452" align="left" class="text6"><input name="keywords" type="text" size="35" /></td> </tr> <tr> <td align="right" valign="top" class="text6">country : </td> <td align="left" class="text6"><select name="country"> <option value="Afghanistan">Afghanistan</option> <option value="Albania">Albania</option> <option value="Algeria">Algeria</option> <option value="American Samoa">American Samoa</option> <option value="Andorra">Andorra</option> </select></td> </tr> <tr> <td align="right" valign="top" class="text6">gender : </td> <td align="left" class="text7"><input name="gender" type="radio" value="Male" /> male <input name="gender" type="radio" value="Female" /> female</td> </tr> <tr> <td align="right" valign="top" class="text6">last employed position : </td> <td align="left" valign="top" class="text6"><input name="lastposition" type="text" size="35" /></td> </tr> <tr> <td align="right" valign="top" class="text6"> </td> <td> </td> <td><span class="text6"> <input type="submit" name="Submit" value="Search by Keywords" class="textfield1" /> <span class="text7"> <input type="hidden" name="id4" value="2" /> </span></span></td> </tr></form> <tr> <td colspan="3" bgcolor="#999999" class="text2">Search by Email </td> </tr> <tr> <td colspan="3" align="right" valign="top" class="text6"><img src="images/spacer.gif" width="10" height="10" /></td> </tr> <tr> <td align="right"><span class="text6">email : </span></td> <td align="right"> </td> <form action="searchcnddate.php?id=3" method="post"> <td align="left" class="text7"> <input name="email" type="text" size="35" /> <input type="submit" name="Submit2" value="Search Email" class="textfield1"></td> </form></tr> <tr> <td colspan="3" align="right" valign="top" class="text6"> </td> </tr> <tr> <td colspan="3" bgcolor="#999999" class="text2">Search by Candidate Name </td> </tr> <tr> <td colspan="3" align="right" valign="top" class="text6"><img src="images/spacer.gif" width="10" height="10" /></td> </tr> <tr> <td align="right" valign="top" class="text6">name : </td> <td align="right" valign="top" class="text6"> </td> <form action="searchcnddate.php?id=4" method="post"> <td align="left" valign="top" class="text6"> <input name="name" type="text" size="35" /> <input type="submit" name="Submit22" value="Search Name" class="textfield1"></td> </form></tr> <tr> <td colspan="3" align="right" class="text6"> </td> </tr> <tr> <td colspan="3" bgcolor="#999999" class="text2">Keyword by Job Specialization </td> </tr> <tr> <td colspan="3" align="right" valign="top" class="text6"><img src="images/spacer.gif" width="10" height="10" /></td> </tr> <tr> <td align="right" valign="top" class="text6">specialization : </td> <td align="right" valign="top" class="text6"> </td> <form action="searchcnddate.php?id=5" method="post"> <td align="left" valign="top" class="text6"><select name="specialization"> <option value="" selected>-- select specialization here --</option> <? $uSql = "SELECT specialization FROM specialization"; $uResult = mysql_query($uSql, $connection); if(!$uResult){ echo 'no data found'; }else{ while($uRow = mysql_fetch_array($uResult)){ ?> <option value="<?= $uRow[specialization]?>"> <?= $uRow[specialization]?> </option> <? } } ?> </select> <input type="submit" name="Submit222" value="Search Specialization" class="textfield1" /></td> </form></tr> <tr> <td colspan="3" align="right" valign="top" class="text6"> </td> </tr> </table> and this is the code for my display page <?php session_start(); if (session_is_registered("username")){ $id = $_POST['id']; include("pagina/my_pagina_class.php"); include 'db_connect.php'; //establish query array $query_array = array(); //append each input field into a new index //in the query_array if the user selected //it or entered information in the field if(!empty($_POST['keywords'])){ $query_array[] = "resume LIKE '%". $_POST['keywords'] ."%'"; } if(!empty($_POST['country'])){ $query_array[] = "country = '". $_POST['country'] ."'"; } if(!empty($_POST['gender'])){ $query_array[] = "gender = '". $_POST['gender'] ."'"; } if(!empty($_POST['lastposition'])){ $query_array[] = "currentposition LIKE '%". $_POST['lastposition'] ."%'"; } //-- if(!empty($_POST['keywords2'])){ $query_array[] = "lname LIKE '%". $_POST['keywords2'] ."%' OR fname LIKE '%". $_POST['keywords2'] ."%' OR resume LIKE '%". $_POST['keywords2'] ."%' OR email LIKE '%". $_POST['keywords2'] ."%'"; } //turn array into string $query_string = implode(" AND ", $query_array); //-- $test = new JHpage; $test->sql = "SELECT * FROM applicant WHERE ". $query_string .""; //$test->sql = "SELECT * FROM applicant WHERE specialization LIKE '%". $sort3 ."%' ORDER BY ".$sort1 ." ".$sort2.""; // the (basic) sql statement (use the SQL whatever you like) $result = $test->get_page_result(); // result set $num_rows = $test->get_page_num_rows(); // number of records in result set $nav_links = $test->navigation(" | ", "currentStyle"); // the navigation links (define a CSS class selector for the current link) $nav_info = $test->page_info(); // information about the number of records on page ("to" is the text between the number) $simple_nav_links = $test->back_forward_link(true); // the navigation with only the back and forward links, use true to use images $total_recs = $test->get_total_rows(); // the total number of records ?> <script type="text/JavaScript"> <!-- function MM_openBrWindow(theURL,winName,features) { //v2.0 window.open(theURL,winName,features); } //--> </script> <table width="100" border="0" cellspacing="0" cellpadding="0"> <tr> <td><img src="../images/spacer.gif" width="6" height="10"></td> <td><table width="216" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="3" valign="top" bgcolor="#3261BB"><img src="../resume/images/spacer.gif" width="1" height="1"></td> </tr> <tr> <td align="left" bgcolor="#3261BB" width="1"><img src="../resume/images/spacer.gif" width="1" height="1"></td> <td width="214" valign="top"> <table width="897" border="0" cellspacing="2" cellpadding="0"> <tr> <td colspan="6" align="right"><form method="post" action="searchcnddate.php?id=2"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="407"><span class="text6"> <?php echo " total record found: " .$total_recs; ?> </span></td> <td width="486" align="right" class="text6">new search : <input type="text" name="keywords2" value="enter keywords"> <input type="submit" name="Submit" value="search" /> </td> </tr> </table> </form></td> </tr> <tr> <td colspan="6"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="60%" align="left" class="text8"> </td> <td width="39%" align="right"><!-- nav top --> <? echo "<span class='link1'>".$nav_links."</span>"; ?> </td> <td width="1%" align="right"><img src="../images/spacer.gif" width="1" height="1" /></td> </tr> </table></td> </tr> <tr> <td width="68" align="center" bgcolor="#83C2ED" class="text5">ID</td> <td width="320" align="center" valign="top" bgcolor="#83C2ED" class="text5">name</td> <td width="220" align="center" bgcolor="#83C2ED" class="text5">email</td> <td width="163" align="center" bgcolor="#83C2ED" class="text5">last employed position </td> <td width="125" align="center" bgcolor="#83C2ED" class="text5">date registered </td> </tr> <?php for ($i = 0; $i < $num_rows; $i++) { $appid = mysql_result($result, $i, "appid"); $fname = mysql_result($result, $i, "fname"); $lname = mysql_result($result, $i, "lname"); $email = mysql_result($result, $i, "email"); $currentposition = mysql_result($result, $i, "currentposition"); $dateregistered = mysql_result($result, $i, "dateregistered"); ?> <tr> <td align="center" bgcolor="#FFFFCC" class="text8"><span class="text5"> </span> A<? echo ($appid <= 9) ? $appid : $appid;?> </td> <td bgcolor="#FFFFCC"> <a href="javascript:;" class="link1" onClick="MM_openBrWindow('resume/preview.php?appid=<? echo "$appid"; ?>','','scrollbars=yes,width=760')"> <? echo " ".$fname." ".$lname." "; ?></a></td> <td bgcolor="#FFFFCC" class="text8"> <? echo "$email";?> </td> <td bgcolor="#FFFFCC" class="text8"> <? echo "$currentposition";?><br></td> <td bgcolor="#FFFFCC" class="text8"><? echo "$dateregistered";?></td> <? echo "</td></tr>"; ?> <? } ?> <tr> <td colspan="6" bgcolor="#83C2ED"><img src="../images/spacer.gif" width="10" height="2" /></td> </tr> <tr> <td colspan="6"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="60%" align="left" class="text8"> </td> <td width="39%" align="right"><!-- nav top --> <? echo "<span class='link1'>".$nav_links."</span>"; ?> </td> <td width="1%" align="right"><img src="../images/spacer.gif" width="1" height="1" /></td> </tr> </table></td> </tr> <tr> <td colspan="6"> </td> </tr> </table> </td> <td align="right" bgcolor="#3261BB" width="1"><img src="../resume/images/spacer.gif" width="1" height="1"></td> </tr> <tr> <td colspan="3" valign="top" bgcolor="#3261BB"><img src="../resume/images/spacer.gif" width="1" height="1"></td> </tr> </table></td> <td><img src="../images/spacer.gif" width="6" height="10"></td> </tr> </table> <? }else{ echo "<font face=\"Arial\">You are not authorized to access this page ... Please <a href='../index.php'>Login</a></font>"; } ?> hope you could help me with this. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/56641-need-help-on-my-display-page-with-pagination/ Share on other sites More sharing options...
teng84 Posted June 22, 2007 Share Posted June 22, 2007 whats the error? or prob ASTIG!! Quote Link to comment https://forums.phpfreaks.com/topic/56641-need-help-on-my-display-page-with-pagination/#findComment-279729 Share on other sites More sharing options...
pixeltrace Posted June 22, 2007 Author Share Posted June 22, 2007 this is the error Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\hosting\webhost4life\member\diorgrace\admean\pagina\my_pagina_class.php on line 90 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\hosting\webhost4life\member\diorgrace\admean\pagina\my_pagina_class.php on line 63 Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in c:\hosting\webhost4life\member\diorgrace\admean\pagina\my_pagina_class.php on line 68 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\hosting\webhost4life\member\diorgrace\admean\pagina\my_pagina_class.php on line 63 Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in c:\hosting\webhost4life\member\diorgrace\admean\pagina\my_pagina_class.php on line 68 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\hosting\webhost4life\member\diorgrace\admean\pagina\my_pagina_class.php on line 63 Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in c:\hosting\webhost4life\member\diorgrace\admean\pagina\my_pagina_class.php on line 68 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\hosting\webhost4life\member\diorgrace\admean\pagina\my_pagina_class.php on line 63 Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in c:\hosting\webhost4life\member\diorgrace\admean\pagina\my_pagina_class.php on line 68 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\hosting\webhost4life\member\diorgrace\admean\pagina\my_pagina_class.php on line 63 Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in c:\hosting\webhost4life\member\diorgrace\admean\pagina\my_pagina_class.php on line 68 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\hosting\webhost4life\member\diorgrace\admean\pagina\my_pagina_class.php on line 63 Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in c:\hosting\webhost4life\member\diorgrace\admean\pagina\my_pagina_class.php on line 68 actually i noticed, since i print the $test so i will see whats happening on my query. i noticed that on my first page the query result is this jhpage Object ( [sql] => SELECT * FROM applicant WHERE country = 'Singapore' [result] => [outstanding_rows] => [get_var] => page [rows_on_page] => 20 [max_rows] => 0 ) but when i click on page 2 the query result is this jhpage Object ( [sql] => SELECT * FROM applicant WHERE [result] => [outstanding_rows] => [get_var] => page [rows_on_page] => 20 [max_rows] => 0 ) the value of the country ='Singapore' is gone i think it has something to do with the POST and GET function but i dont know how to fix it. hope you could help me with this. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/56641-need-help-on-my-display-page-with-pagination/#findComment-279733 Share on other sites More sharing options...
teng84 Posted June 22, 2007 Share Posted June 22, 2007 $test->sql = "SELECT * FROM applicant WHERE ". $query_string .""; sure about that can i see the piece of the classsss AStIG!! Quote Link to comment https://forums.phpfreaks.com/topic/56641-need-help-on-my-display-page-with-pagination/#findComment-279742 Share on other sites More sharing options...
pixeltrace Posted June 22, 2007 Author Share Posted June 22, 2007 this is the code inside my_pagina_class.php require("db_config.php"); error_reporting(E_ALL); // only for testing class JHpage { var $sql; var $result; var $outstanding_rows = false; var $get_var; var $rows_on_page; var $max_rows; // constructor function JHpage($rows = 0) { $this->connect_db(); $this->max_rows = $rows; $this->get_var = QS_VAR; $this->rows_on_page = NUM_ROWS; } // sets the current page number function set_page() { $page = (isset($_REQUEST[$this->get_var]) && $_REQUEST[$this->get_var] != "") ? $_REQUEST[$this->get_var] : 0; return $page; } // gets the total number of records function get_total_rows() { $tmp_result = mysql_query($this->sql); $all_rows = mysql_num_rows($tmp_result); if (!empty($this->max_rows) && $all_rows > $this->max_rows) { $all_rows = $this->max_rows; $this->outstanding_rows = true; } mysql_free_result($tmp_result); return $all_rows; } // database connection function connect_db() { $conn_str = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD); mysql_select_db(DB_NAME, $conn_str); } // get the totale number of result pages function get_num_pages() { $number_pages = ceil($this->get_total_rows() / $this->rows_on_page); return $number_pages; } // returns the records for the current page function get_page_result() { $start = $this->set_page() * $this->rows_on_page; $page_sql = sprintf("%s LIMIT %s, %s", $this->sql, $start, $this->rows_on_page); $this->result = mysql_query($page_sql); return $this->result; } // get the number of rows on the current page function get_page_num_rows() { $num_rows = mysql_num_rows($this->result); return $num_rows; } // free the database result function free_page_result() { mysql_free_result($this->result); } // function to handle other querystring than the page variable function rebuild_qs($curr_var) { if (!empty($_SERVER['QUERY_STRING'])) { $parts = explode("&", $_SERVER['QUERY_STRING']); $newParts = array(); foreach ($parts as $val) { if (stristr($val, $curr_var) == false) { array_push($newParts, $val); } } if (count($newParts) != 0) { $qs = "&".implode("&", $newParts); } else { return false; } return $qs; // this is your new created query string } else { return false; } } // this method will return the navigation links for the conplete recordset function navigation($separator = " | ", $css_current = "", $back_forward = false, $use_images = false) { $max_links = NUM_LINKS; $curr_pages = $this->set_page(); $all_pages = $this->get_num_pages() - 1; $var = $this->get_var; $navi_string = ""; if (!$back_forward) { $max_links = ($max_links < 2) ? 2 : $max_links; } if ($curr_pages <= $all_pages && $curr_pages >= 0) { if ($curr_pages > ceil($max_links/2)) { $start = ($curr_pages - ceil($max_links/2) > 0) ? $curr_pages - ceil($max_links/2) : 1; $end = $curr_pages + ceil($max_links/2); if ($end >= $all_pages) { $end = $all_pages + 1; $start = ($all_pages - ($max_links - 1) > 0) ? $all_pages - ($max_links - 1) : 1; } } else { $start = 0; $end = ($all_pages >= $max_links) ? $max_links : $all_pages + 1; } if($all_pages >= 1) { $forward = $curr_pages + 1; $backward = $curr_pages - 1; // the text two labels are new sinds ver 1.02 $lbl_forward = $this->build_back_or_forward("forward", $use_images); $lbl_backward = $this->build_back_or_forward("backward", $use_images); $navi_string = ($curr_pages > 0) ? "<a class='link1' href=\"".$_SERVER['PHP_SELF']."?".$var."=".$backward.$this->rebuild_qs($var)."\">".$lbl_backward."</a> " : $lbl_backward." "; if (!$back_forward) { for($a = $start + 1; $a <= $end; $a++){ $theNext = $a - 1; // because a array start with 0 if ($theNext != $curr_pages) { $navi_string .= "<a class='link1' href=\"".$_SERVER['PHP_SELF']."?".$var."=".$theNext.$this->rebuild_qs($var)."\">"; $navi_string .= $a."</a>"; $navi_string .= ($theNext < ($end - 1)) ? $separator : ""; } else { $navi_string .= ($css_current != "") ? "<span class='text6'\"".$css_current."\">".$a."</span>" : $a; $navi_string .= ($theNext < ($end - 1)) ? $separator : ""; } } } $navi_string .= ($curr_pages < $all_pages) ? " <a class='link1' href=\"".$_SERVER['PHP_SELF']."?".$var."=".$forward.$this->rebuild_qs($var)."\">".$lbl_forward."</a>" : " ".$lbl_forward; } } return $navi_string; } // function to create the back/forward elements; $what = forward or backward // type = text or img function build_back_or_forward($what, $img = false) { $label['text']['forward'] = STR_FWD; $label['text']['backward'] = STR_BWD; $label['img']['forward'] = IMG_FWD; $label['img']['backward'] = IMG_BWD; if ($img) { // $img_info = getimagesize($label['img'][$what]); //$label = "<img src=\"".$label['img'][$what]."\" ".$img_info[3]." border=\"0\">"; } else { $label = $label['text'][$what]; } return $label; } // this info will tell the visitor which number of records are shown on the current page function page_info($str = "Result: %d - %d of %d") { $first_rec_no = ($this->set_page() * $this->rows_on_page) + 1; $last_rec_no = $first_rec_no + $this->rows_on_page - 1; $last_rec_no = ($last_rec_no > $this->get_total_rows()) ? $this->get_total_rows() : $last_rec_no; $info = sprintf($str, $first_rec_no, $last_rec_no, $this->get_total_rows()); return $info; } // simple method to show only the page back and forward link. function back_forward_link($images = true) { $simple_links = $this->navigation(" ", "", false, $images); return $simple_links; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/56641-need-help-on-my-display-page-with-pagination/#findComment-279746 Share on other sites More sharing options...
teng84 Posted June 22, 2007 Share Posted June 22, 2007 $query_string = implode(" AND ", $query_array); $test->sql = "SELECT * FROM applicant WHERE ". $query_string .""; echo first the query "SELECT * FROM applicant WHERE ". $query_string .""; then see what is wrong Quote Link to comment https://forums.phpfreaks.com/topic/56641-need-help-on-my-display-page-with-pagination/#findComment-279754 Share on other sites More sharing options...
pixeltrace Posted June 22, 2007 Author Share Posted June 22, 2007 i already printed the error on that one from my previous post. on my first page here is the result jhpage Object ( [sql] => SELECT * FROM applicant WHERE country = 'Singapore' [result] => [outstanding_rows] => [get_var] => page [rows_on_page] => 20 [max_rows] => 0 ) if i click the second page here is the code jhpage Object ( [sql] => SELECT * FROM applicant WHERE [result] => [outstanding_rows] => [get_var] => page [rows_on_page] => 20 [max_rows] => 0 ) i notice that the country='Singpaore' is gone when i click on the second page i think it has something to do with the POST and GET function but i dont know how to fix it. hope you could help me with this thanks! Quote Link to comment https://forums.phpfreaks.com/topic/56641-need-help-on-my-display-page-with-pagination/#findComment-279759 Share on other sites More sharing options...
teng84 Posted June 22, 2007 Share Posted June 22, 2007 if(!empty($_POST['keywords'])){ $query_array[] = "resume LIKE '%". $_POST['keywords'] ."%'"; } if(!empty($_POST['country'])){ $query_array[] = "country = '". $_POST['country'] ."'"; } if(!empty($_POST['gender'])){ $query_array[] = "gender = '". $_POST['gender'] ."'"; } if(!empty($_POST['lastposition'])){ $query_array[] = "currentposition LIKE '%". $_POST['lastposition'] ."%'"; } ^^^ you initialize the vlue with the post u use for the query and whem click the link post is no longer available so you have to use get now add those valu on the link and perform the get method hope you understand any way ask again if thats sounds strange ASTIG!!! Quote Link to comment https://forums.phpfreaks.com/topic/56641-need-help-on-my-display-page-with-pagination/#findComment-279763 Share on other sites More sharing options...
pixeltrace Posted June 22, 2007 Author Share Posted June 22, 2007 actually i replaced everything with GET already including the method in my form but its still not working. Quote Link to comment https://forums.phpfreaks.com/topic/56641-need-help-on-my-display-page-with-pagination/#findComment-279768 Share on other sites More sharing options...
teng84 Posted June 22, 2007 Share Posted June 22, 2007 did have the link like this link.php?value1=$_POST['valu here']&value2=$_POST['valu here']; ASTIG!!! Quote Link to comment https://forums.phpfreaks.com/topic/56641-need-help-on-my-display-page-with-pagination/#findComment-279770 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.