Jump to content

phpwolf

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

phpwolf's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi If I understand correctly, you want to have a login form as shown in the pic above. I haven't read or tried using your css code, coz I just don't have time right now, but I can help you with this. Using HTML & CSS: Make an "invisible" HTML form, insert every html element below into it, and make the outer frame a table ( the outermost grey line ), and then close the form element. OR Make the outer frame a table ( the outermost grey line ), and insert an "invisible" form elemnent, and have the closing tag just before the closing tag of the table. ( Invisible meaning the same color as the background ) In the table make 3 table rows: <tr> </tr> In each table row, insert 2 sets of table data's: <td> </td>, In the first <td> </td> insert: Username: In the second <td> </td>, still in the first table row, Insert a Input box <input> </input> ( for user input ), Do the same for the 2nd table row, ( insert Password: instead of Username: ), In the 3rd table row, leave the first <td> </td> empty, For the Login Button: use the <button> </button> tags, Lastly: Use CSS for the Sizes and styling of the HTML elements: Give a Class name for all table rows, Give a Class name for first COLUMN of td's, and a Class name for the second COLUMN of td's, and a Id name for the Login button. I hope it helped
  2. Hi all, Below is a much simplified and optimized version of my other search codes, to make it easier to find and solve the error / problem. The problem is that the script does not page correctly. It does however show page 1 correctly. Any suggestions or possible solutions guys? I've done all the tutorials I have found, and also used free code snippets. They simply don't cover multiple keyword searching with user selected sortorder or rowsperpage. This version uses the "build-query method" where the seach query is built when the searchvariables are set. This is much more efficient than the elseif approach. Here is the database setup: Database name: shopdb Table name: shopdbtable Columns: ID, STATUS, PRODUCT Add a STATUS column with phpmyadmin: In structure screen, Make a new field: STATUS Type: ENUM Length Values: 'Y','N' Default: As defined: Y Here is the optimized version: <?php session_start(); ?> <html> <body> <form method="post" action="http://localhost/rssearch.php"> <p> Product Search: <input name="psearch" size="20" maxlength="80"> </input> </p> <p> Display Number On Page: <select name="rowsperpage"> <option value="10" selected="">10</option> <option value="20">20</option> <option value="30">30</option> <option value="40">40</option> <option value="50">50</option> <option value="100">100</option> </select> </p> <p> Sort Order: <select name="sortorder"> <option value="PRODUCT ASC">A - Z</option> <option value="PRODUCT DESC">Z - A</option> </select> </p> <button TYPE="submit" NAME="submitform">SEARCH! </button> </form> <?php $conn = mysql_connect('localhost','root','') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('shopdb',$conn) or trigger_error("SQL", E_USER_ERROR); if (isset($_POST['submitform'])) { unset($_SESSION); $_SESSION['rowsperpage'] = @$_POST['rowsperpage']; $_SESSION['sortorder'] = @$_POST['sortorder']; $_SESSION['psearchfil'] = @$_POST['psearchfil']; } var_dump($_SESSION['psearchfil']); var_dump($_SESSION['rowsperpage']); var_dump($_SESSION['sortorder']); if (!isset($_SESSION['psearchfil']) And !empty($_POST['psearch'])) { $_SESSION['psearchfil'] = preg_replace('/[^a-zA-Z0-9]/', '', $_POST['psearch']); } if (isset($_SESSION['psearchfil'])) { $sqlcount = "SELECT COUNT(PRODUCT) FROM shopdbtable WHERE `PRODUCT` REGEXP '$_SESSION[psearchfil]'"; } var_dump($sqlcount); $result = mysql_query($sqlcount, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; $totalpages = ceil($numrows / $_SESSION['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) * $_SESSION['rowsperpage']; $sqlsearch = "SELECT ID, STATUS, PRODUCT FROM shopdbtable WHERE STATUS='Y' "; if (isset($_SESSION['psearchfil'])) { $sqlsearch .= " AND `PRODUCT` REGEXP '$_SESSION[psearchfil]' "; } if (isset($_SESSION['psearchfil'])) { $sqlsearch .= " ORDER BY $_SESSION[sortorder] LIMIT $offset, $_SESSION[rowsperpage] "; } var_dump($sqlsearch); $result = mysql_query($sqlsearch, $conn) or trigger_error("SQL", E_USER_ERROR); while ($list = mysql_fetch_assoc($result)) { echo $list['ID'] . $list['PRODUCT'] . "<br />"; } $range = 3; if ($currentpage > 1) { echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; $prevpage = $currentpage - 1; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { if (($x > 0) && ($x <= $totalpages)) { if ($x == $currentpage) { echo " [<b>$x</b>] "; } else { echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } } } if ($currentpage != $totalpages) { $nextpage = $currentpage + 1; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } var_dump ($sqlsearch); var_dump ($_SESSION['psearchfil']); mysql_close(); ?> </body> </html> Any possible solutions or suggestions or guidance in solving this issue is much appreciated Thank you
  3. Greetings Everyone I'm having a seemingly unsolvable problem with my search and pagination script. //www.phpfreaks.com/forums/Smileys/nrg_alpha/shrug.gif http://www.phpfreaks.com/forums/Smileys/nrg_alpha/shrug.gifhttp://www.phpfreaks.com/forums/Smileys/nrg_alpha/shrug.gifhttp://www.phpfreaks.com/forums/Smileys/nrg_alpha/shrug.gifhttp://www.phpfreaks.com/forums/Smileys/nrg_alpha/shrug.gifhttp://www.phpfreaks.com/forums/Smileys/nrg_alpha/shrug.gif Information about the script: My script based on crayon violent tut in the tutorials section here on phpfreaks. Feel free to use it, when it is solved. A little about myself and my project: This is my first PHP & MYSQL project and also my introduction to Server-Side scripting. It is really great to be able to have so much control over the website and to be able to do things that you want, but can't do in HTML, but it gets really frustrating when faced with a problem that you can't solve immediatly or by yourself. However, it is also a great opportunity to learn when faced with problems. I've learned about SESSIONS and Conditional Statements ( If, elesif, switch, break, for, ) and about how to write code differently but get the same result ( Eg: elseif and switch ). Most of all, I think I've got acquainted with PAAAAAAAAAATTTTTTTTTTIIIIIIIIIEEEEEEEEEEENNNNNNNNNCCCCCCCCCEEEEEEEEEEE, DETERMINATION AND BELIEVING THAT I CAN DO THIS. ( and getting [sqaure] [eyes] ) But like all of you guys we work with time constrictions and I've now spent way too much time than what is neccassary trying to solve these problems, it is now time for this problem to be solved so I can move on to another section of the website design, otherwise it's not getting done. This script is really important because my whole website is based on it being able to handle 4 search values. ( The script below is only 3 to make it easier to work with ) This is why forums like phpfreaks is so great because we have the chance to get help and get things done. I REEEEEEEEEEEEEEEEEEAAAAAAAAAAAAALLLLLLYYYYY hope you guys & gurus can help me out. Anyways, on with the problemsolving! Problem 1: It doesn't display page 2! It correctly displays page 1. ( It somehow overwrites the session variables, because it displays the message for when no value is entered ). How can the session variables be passed correctly and not be overwritten? Problem 2: For sequrity reasons I've renamed all the variables and tablefields and making a new database and table, etc... But the script now gives following error: Fatal error: SQL in /opt/lampp/htdocs/rssearch.php on line 254. What are possible causes? ( My original script works correctly, except for overwriting the session variables ) Here is the Full Script: <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <head> <title> </title> </head> <html> <body> <form method="post" action="http://localhost/search.php"> <p> Brand Name Search: <input name="bnsearch" size="20" maxlength="80"> </input> </p> <p> Product Search: <input name="psearch" size="20" maxlength="80"> </input> </p> <p> Shop Location Search: <input name="slsearch" size="20" maxlength="80"> </input> </p> </p> <p> Display Number On Page: <select name="rowsperpage"> <option value="10" selected="">10</option> <option value="20">20</option> <option value="30">30</option> <option value="40">40</option> <option value="50">50</option> <option value="100">100</option> </select> </p> <p> Sort Order: <select name="sortorder"> <option value="ID ASC">A - Z</option> <option value="ID DESC">Z - A</option> </select> </p> <button TYPE="submit" NAME="submitform">SEARCH! </button> </form> <?php $conn = mysql_connect('localhost','root','') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('shopdb',$conn) or trigger_error("SQL", E_USER_ERROR); if (isset($_POST['submitform'])) { unset($_SESSION); $_SESSION['rowsperpage'] = @$_POST['rowsperpage']; $_SESSION['sortorder'] = @$_POST['sortorder']; } $_SESSION['rowsperpage']; $_SESSION['sortorder']; if(isset($_SESSION['sqlsearch']) And isset($_SESSION['sqlcount'])) { $_SESSION['sqlsearch']; $_SESSION['sqlcount']; } if (!isset($_SESSION['bnsfil']) And !empty($_POST['bnsearch'])) { $_SESSION['bnsfil'] = preg_replace('/[^a-zA-Z0-9]/', '', $_POST['bnsearch']); } elseif(!isset($_SESSION['bnsfil']) And empty($_POST['bnsfil'])) { $_SESSION['bnsfil'] = ""; } if (!isset($_SESSION['psearch']) And !empty($_POST['psearch'])) { $_SESSION['psfil'] = preg_replace('/[^a-zA-Z0-9]/', '', $_POST['psearch']); } elseif (!isset($_SESSION['psearch']) And empty($_POST['psearch'])) { $_SESSION['psfil'] = "" ; } if (!isset($_SESSION['slsfil']) And !empty($_POST['slsearch'])) { $_SESSION['slsfil'] = preg_replace('/[^a-zA-Z0-9]/', '', $_POST['slsearch']); } elseif(!isset($_SESSION['slsfil']) And empty($_POST['slsfil'])) { $_SESSION['slsfil'] = ""; } var_dump ($_SESSION['bnsfil']); var_dump ($_SESSION['psfil']); var_dump ($_SESSION['slsfil']); if (!empty($_SESSION['bnsfil']) And empty($_SESSION['psfil']) And empty($_SESSION['slsfil'])) { $_SESSION['sqlcount'] = "SELECT COUNT (BRANDNAME) FROM shopdbtable WHERE `BRANDNAME` REGEXP '$_SESSION[bnsfil]'"; } if (empty($_SESSION['bnsfil']) And !empty($_SESSION['psfil']) And empty($_SESSION['slsfil'])) { $_SESSION['sqlcount'] = "SELECT COUNT(PRODUCT) FROM shopdbtable WHERE `PRODUCT` REGEXP '$_SESSION[psfil]'"; } if (empty($_SESSION['bnsfil']) And empty($_SESSION['psfil']) And !empty($_SESSION['slsfil'])) { $_SESSION['sqlcount'] = "SELECT COUNT(SHOPLOCATION) FROM shopdbtable WHERE `SHOPLOCATION` REGEXP '$_SESSION[slsfil]'"; } if (!empty($_SESSION['bnsfil']) And !empty($_SESSION['psfil']) And !empty($_SESSION['slsfil'])) { $_SESSION['sqlcount'] = "SELECT COUNT(*) FROM shopdbtable WHERE `BRANDNAME` REGEXP '$_SESSION[bnsfil]' AND `PRODUCT` REGEXP '$_SESSION[psfil]' AND `SHOPLOCATION` REGEXP '$_SESSION[slsfil]'"; } if (!empty($_SESSION['bnsfil']) And empty($_SESSION['psfil']) And !empty($_SESSION['slsfil'])) { $_SESSION['sqlcount'] = "SELECT COUNT(*) FROM shopdbtable WHERE `BRANDNAME` REGEXP '$_SESSION[bnsfil]' AND `SHOPLOCATION` REGEXP'$_SESSION[slsfil]'"; } if (empty($_SESSION['bnsfil']) And !empty($_SESSION['psfil']) And !empty($_SESSION['slsfil'])) { $_SESSION['sqlcount'] = "SELECT COUNT(*) FROM shopdbtable WHERE `PRODUCT` REGEXP '$_SESSION[psfil]' AND `SHOPLOCATION` REGEXP'$_SESSION[slsfil]'"; } if (!empty($_SESSION['bnsfil']) And !empty($_SESSION['psfil']) And empty($_SESSION['slsfil'])) { $_SESSION['sqlcount'] = "SELECT COUNT(*) FROM shopdbtable WHERE `BRANDNAME` REGEXP '$_SESSION[bnsfil]' AND `PRODUCT` REGEXP'$_SESSION[psfil]'"; } if ( empty($_SESSION['bnsfil']) And empty($_SESSION['psfil']) And empty($_SESSION['slsfil'])) { $_SESSION['sqlcount'] = "Your search query did not match any records. Please enter another value."; } var_dump ($_SESSION['sqlcount']); $result = mysql_query($_SESSION['sqlcount'], $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; $totalpages = ceil($numrows / $_SESSION['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) * $_SESSION['rowsperpage']; if (!empty($_SESSION['bnsfil']) And empty($_SESSION['psfil']) And empty($_SESSION['slsfil'])) { $_SESSION['sqlsearch'] = "SELECT ID, BRANDNAME, FROM shopdbtable WHERE `BRANDNAME` REGEXP '$_SESSION[bnsfil]' ORDER BY $_SESSION[sortorder] LIMIT $offset, $_SESSION[rowsperpage]"; } if ( empty($_SESSION['bnsfil']) And !empty($_SESSION['psfil']) And empty($_SESSION['slsfil'])) { $_SESSION['sqlsearch'] = "SELECT ID, PRODUCT, FROM shopdbtable WHERE `PRODUCT` REGEXP '$_SESSION[psfil]' ORDER BY $_SESSION[sortorder] LIMIT $offset, $_SESSION[rowsperpage]"; } if ( empty($_SESSION['bnsfil']) And empty($_SESSION['psfil']) And !empty($_SESSION['slsfil'])) { $_SESSION['sqlsearch'] = "SELECT ID, SHOPLOCATION, FROM shopdbtable WHERE `SHOPLOCATION` REGEXP '$_SESSION[slsfil]' ORDER BY $_SESSION[sortorder] LIMIT $offset, $_SESSION[rowsperpage]"; } if ( !empty($_SESSION['bnsfil']) And !empty($_SESSION['psfil']) And !empty($_SESSION['slsfil'])) { $_SESSION['sqlsearch'] = "SELECT ID, BRANDNAME, PRODUCT, SHOPLOCATION, FROM shopdbtable WHERE `BRANDNAME` REGEXP '$_SESSION[bnsfil]' AND `PRODUCT` REGEXP '$_SESSION[psfil]' AND `SHOPLOCATION` REGEXP '$_SESSION[slsfil]' ORDER BY $_SESSION[sortorder] LIMIT $offset, $_SESSION[rowsperpage]"; } if ( !empty($_SESSION['bnsfil']) And empty($_SESSION['psfil']) And !empty($_SESSION['slsfil'])) { $_SESSION['sqlsearch'] = "SELECT ID, BRANDNAME, SHOPLOCATION, FROM shopdbtable WHERE `BRANDNAME` REGEXP '$_SESSION[bnsfil]' AND `SHOPLOCATION` REGEXP '$_SESSION[slsfil]' ORDER BY $_SESSION[sortorder] LIMIT $offset, $_SESSION[rowsperpage]"; } if ( empty($_SESSION['bnsfil']) And !empty($_SESSION['psfil']) And !empty($_SESSION['slsfil'])) { $_SESSION['sqlsearch'] = "SELECT ID, PRODUCT, SHOPLOCATION, FROM shopdbtable WHERE `PRODUCT` REGEXP '$_SESSION[psfil]' AND `SHOPLOCATION` REGEXP '$_SESSION[slsfil]' ORDER BY $_SESSION[sortorder] LIMIT $offset, $_SESSION[rowsperpage]"; } if ( !empty($_SESSION['bnsfil']) And !empty($_SESSION['psfil']) And empty($_SESSION['slsfil'])) { $_SESSION['sqlsearch'] = "SELECT ID, BRANDNAME, PRODUCT, FROM shopdbtable WHERE `BRANDNAME` REGEXP '$_SESSION[bnsfil]' AND `PRODUCT` REGEXP '$_SESSION[psfil]' ORDER BY $_SESSION[sortorder] LIMIT $offset, $_SESSION[rowsperpage]"; } /* if (empty($_SESSION['bnsfil']) And empty($_SESSION['psfil']) And empty($_SESSION['slsfil'])) { echo "Enter another value."; } */ var_dump ($_SESSION['sqlsearch']); $result = mysql_query($_SESSION['sqlsearch'], $conn) or trigger_error("SQL", E_USER_ERROR); while ($list = mysql_fetch_assoc($result)) { echo $list['ID'] . " : " . $list['BRANDNAME'] . "<br />"; } $range = 3; if ($currentpage > 1) { echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; $prevpage = $currentpage - 1; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { if (($x > 0) && ($x <= $totalpages)) { if ($x == $currentpage) { echo " [<b>$x</b>] "; } else { echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } } } if ($currentpage != $totalpages) { $nextpage = $currentpage + 1; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } mysql_close(); ?> </body> </html> All your help and insights are greatly appreciatedhttp://www.phpfreaks.com/forums/Smileys/nrg_alpha/happy-02.gif Thank you
  4. Solved It! After viewing the MYSQL part of the forum, i've found this to work: Change line: $_SESSION['mysqlquery'] = "SELECT COUNT(*) FROM mysqldbtable"; to: $_SESSION['mysqlquery'] = "SELECT COUNT ( CLIENTNAMES ) FROM mysqldbtable WHERE `CLIENTNAMES` REGEXP '$_SESSION[searchvar]'"; This isn't really ideal coz im trying to implement a multi-field search script and this complicates multi search pagination.
  5. Hey guys here's the code again, color formatted. Im not getting anywhere with this script, I've been working on it for a few weeks already, but can't solve it. I've changed the line $_SESSION['mysqlquery'] = "SELECT COUNT(*) FROM mysqldbtable"; a few times, but this doesn't correct the problem, Is there any other way to make the script paginate correctly??? Any help is greatly appreciated Thank you <?php session_start(); $sess = session_id(); var_dump($sess); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <head> </head> <body> <p> <form method="post" action="http://localhost/search.php" name="searchengine"> Search: <input name="search" size="20" maxlength="80"> </input> <p> Display Rows On Page: <select name="rowsperpage"> <option value="10" selected="">10</option> <option value="20">20</option> <option value="30">30</option> <option value="40">40</option> <option value="50">50</option> <option value="100">100</option> </select> </p> <div id="selectsortorder"> Sort Order: <select name="sortorder"> <option value="ID ASC">A - Z</option> <option value="ID DESC">Z - A</option> </select> </div> <button TYPE="submit" NAME="submitform">SEARCH! </button> </form> <?php $conn = mysql_connect('localhost','root','') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('mysqldb',$conn) or trigger_error("SQL", E_USER_ERROR); if (isset($_POST['submitform'])) // If SEARCH! button is pressed, then... { unset($_SESSION); // unset the previous sessionvariables. $rowsperpage= @$_POST['rowsperpage'];// load new $rowsperpage only when SEARCH! Button is pressed. $sortorder = @$_POST['sortorder']; // load new $sortorderperpage only when SEARCH! Button is pressed. } $_SESSION['rowsperpage'] = $rowsperpage; $_SESSION['sortorder'] = $sortorder; if(!isset($_SESSION['searchvar'])) { $searchvar = $_POST['search']; } elseif(isset($_SESSION['searchvar'])) { $searchvar = $_SESSION['searchvar']; } $_SESSION['searchvar'] = $searchvar; var_dump($_SESSION['searchvar']); // find out how many rows are in the table $_SESSION['mysqlquery'] = "SELECT COUNT(*) FROM mysqldbtable"; $result = mysql_query($_SESSION['mysqlquery'], $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page // find out total pages $totalpages = ceil($numrows / $_SESSION['rowsperpage'] ); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $_SESSION['rowsperpage']; $_SESSION['offset'] = $offset; $_SESSION['mysqlquery'] = "SELECT ID, CLIENTNAMES FROM mysqldbtable WHERE `CLIENTNAMES` REGEXP '$_SESSION[searchvar]' ORDER BY $_SESSION[sortorder] LIMIT $_SESSION[offset], $_SESSION[rowsperpage]"; $_SESSION['mysqlquery']; $_SESSION ['result111'] = mysql_query($_SESSION['mysqlquery'], $conn) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($_SESSION ['result111'])) { // echo data echo $list['CLIENTNAMES'] . "<br />"; } // end while // range of num links to show $range = 5; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if mysql_close(); ?> </body>
  6. Hi nilansanjaya, 2nd mysql_query is this one: $_SESSION['mysqlquery'] = "SELECT ID, CLIENTNAMES FROM mysqldbtable WHERE `CLIENTNAMES` REGEXP '$_SESSION[searchvar]' ORDER BY $_SESSION[sortorder] LIMIT $_SESSION[offset], $_SESSION[rowsperpage]"; The problem is that the script makes pagelinks for all rows in the databasetable, and not as it should, which is only make links for the results in the $_SESSION['mysqlquery'] above.
  7. Hello I looked up some other pagination posts here on phpfreaks, and it might be the $_SESSION['mysqlquery'] = "SELECT COUNT(*) FROM mysqldbtable"; statement that is not constructed correctly, but im not sure. Once again, im trying to get the script to only make pagelinks for the rows in the 2nd mysql_query. Here is the search and pagination code again: <?php session_start(); $sess = session_id(); var_dump($sess); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <head> </head> <body> <p> <form method="post" action="http://localhost/search.php" name="searchengine"> Search: <input name="search" size="20" maxlength="80"> </input> <p> Display Rows On Page: <select name="rowsperpage"> <option value="10" selected="">10</option> <option value="20">20</option> <option value="30">30</option> <option value="40">40</option> <option value="50">50</option> <option value="100">100</option> </select> </p> <div id="selectsortorder"> Sort Order: <select name="sortorder"> <option value="ID ASC">A - Z</option> <option value="ID DESC">Z - A</option> </select> </div> <button TYPE="submit" NAME="submitform">SEARCH! </button> </form> <?php $conn = mysql_connect('localhost','root','') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('mysqldb',$conn) or trigger_error("SQL", E_USER_ERROR); if (isset($_POST['submitform'])) // If SEARCH! button is pressed, then... { unset($_SESSION); // unset the previous sessionvariables. $rowsperpage= @$_POST['rowsperpage'];// load new $rowsperpage only when SEARCH! Button is pressed. $sortorder = @$_POST['sortorder']; // load new $sortorderperpage only when SEARCH! Button is pressed. } $_SESSION['rowsperpage'] = $rowsperpage; $_SESSION['sortorder'] = $sortorder; if(!isset($_SESSION['searchvar'])) { $searchvar = $_POST['search']; } elseif(isset($_SESSION['searchvar'])) { $searchvar = $_SESSION['searchvar']; } $_SESSION['searchvar'] = $searchvar; var_dump($_SESSION['searchvar']); // find out how many rows are in the table $_SESSION['mysqlquery'] = "SELECT COUNT(*) FROM mysqldbtable"; $result = mysql_query($_SESSION['mysqlquery'], $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page // find out total pages $totalpages = ceil($numrows / $_SESSION['rowsperpage'] ); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $_SESSION['rowsperpage']; $_SESSION['offset'] = $offset; $_SESSION['mysqlquery'] = "SELECT ID, CLIENTNAMES FROM mysqldbtable WHERE `CLIENTNAMES` REGEXP '$_SESSION[searchvar]' ORDER BY $_SESSION[sortorder] LIMIT $_SESSION[offset], $_SESSION[rowsperpage]"; $_SESSION['mysqlquery']; $_SESSION ['result111'] = mysql_query($_SESSION['mysqlquery'], $conn) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($_SESSION ['result111'])) { // echo data echo $list['CLIENTNAMES'] . "<br />"; } // end while // range of num links to show $range = 5; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if mysql_close(); ?> </body> Any help will be greatly appreciated Thank you
  8. Hi, I'm having a problem with my search and pagintion script. Here is my Setup: Apache 2.2.14 MySQL 5.1.41 PHP 5.3.1 Ubuntu 9... Databasename: mysqldb Table: mysqldbtable Columns: ID, CLIENTNAMES Php file: search.php ( in htdocs folder ) Pagination part is based on the tutorial from Crayon Violent on phpfreaks.com The Best pagination tut on the web! The problem is the script seems to count and make pagelinks for all rows in the databasetable, and not as it should which is the number of rows from the $_SESSION['mysqlquery'] only. Any idea on how to make the script only count and make pagelinks for the results of the $_SESSION['mysqlquery'], and not for all the rows in the table? Any help wil be greatly appreciated. Thanks. [attachment deleted by admin]
×
×
  • 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.