moreira Posted December 12, 2010 Share Posted December 12, 2010 I need some help. I've created a search bar (search.php) that submit the result (resultado.php). Everthing is ok, except the pagination! Results on first page good but the links for the other pages not good (it seems that looses the input information) "Notice: Undefined index: pesquisa in resultado.php on line 6". I tried to work with session but whitout sucess. Can anybody help? the search.php: <table width="200" border="0" align="center" valign="top"> <tr> <td><div align="center"><form id="form1" name="form1" method="get" action="search.php"> <label for="textfield"></label> <input name="pesquisa" type="text" id="pesquisa" value="pesquisar por..." size="26" /> </form> </td> and the resultado.php: <?php include("classes/Pagination.php"); include("classes/config.php"); $dbc = @mysqli_connect(localhost, root, mifa, ocorredorcms); $keyword = trim($_GET['pesquisa']) ; $keyword = mysqli_real_escape_string($dbc, $keyword); //PAGINATION SETTINGS //the pagination requires the total amount of articles $total_records = mysql_num_rows(mysql_query("SELECT * FROM cms_content where title like '%$keyword%' or body like '%$keyword%' or category like '%$keyword%'")); $page = 1; $size = 3; if (isset($_GET['page'])){ $page = (int) $_GET['page']; } //Pagination class $pagination = new Pagination(); //here we use the variable $siteurl which is defined in the configuration.php, should you ever use mod_rewrite to rewrite your url's //it would be a good idea to add the $siteurl variable to your urls, same for images or links to your styles and scripts $pagination->setLink("search.php?page=%s"); $pagination->setPage($page); $pagination->setSize($size); $pagination->setTotalRecords($total_records); //////////// $sql = mysql_query("SELECT * FROM cms_content where title like '%$keyword%' or body like '%$keyword%' or category like '%$keyword%' ". $pagination->getLimitSql()); $sql_num = mysql_num_rows($sql); //if the result of the function mysqli_num_rows IS null then show a message //when we store something into a variable we use = , but when we want to check/compare for something we use == or when comparing strings === if($sql_num == 0): //so if there is nothing show the message echo '<h2>Não foram encontrados resultados para: "'.$_GET['pesquisa'].'"</h2>'; else: //while there are rows print them on the screen if(isset($_GET['artigo'])){ $artigo_id = $_GET['artigo']; $query = mysql_query("SELECT * FROM cms_content WHERE id = {$artigo_id}"); $artigo = mysql_fetch_array($query); } else { $query = mysql_query("SELECT * FROM cms_content where title like '%$keyword%' or body like '%$keyword%' or category like '%$keyword%' ORDER BY id DESC ". $pagination->getLimitSql()); while($artigo = mysql_fetch_array($query)){ echo "<div class=\"artigo-info\">"; echo '<h2><a href="'.$artigo['category'].'.php?artigo='.$artigo['id']."\">" . $artigo['title'] . "</a></h2>"; echo '<p class="style4">' . $artigo['description'] . '</p>'; echo '<j10><a href="'.$artigo['category'].'.php?artigo='.$artigo['id']."\">" . "LER O ARTIGO COMPLETO >" . "</a></j10>"; echo "</div>"; } } $navigation = $pagination->create_links(); echo '<div align="center">' . $navigation . '</div>'; endif; ?> please help Link to comment https://forums.phpfreaks.com/topic/221365-search-bar-results-with-pagination/ Share on other sites More sharing options...
moreira Posted December 12, 2010 Author Share Posted December 12, 2010 anyone knows if i use session start that will save my get[pesquisa] to the nexte page? Best regards, Moreira Link to comment https://forums.phpfreaks.com/topic/221365-search-bar-results-with-pagination/#findComment-1146128 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.