View Full Version : search form errors

02-23-2012, 04:44 PM
I have 2 problems and I can't find them.
1. when no results found... I don't get the message "0 results".
2. when found 90 results (for example) and list them 20/page, when I click [page 2] I get page 2 from all data listed (not only those 90 results).

$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if ($conn){
mysql_select_db("dbname", $conn);
$per_page = 20;
$pages_query = mysql_query ("SELECT COUNT('ID') FROM table WHERE column LIKE '%$word%' AND column LIKE '%$word%'");
$pages = ceil(mysql_result($pages_query, 0) / $per_page);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_page;

$query = "SELECT * FROM table WHERE column LIKE '%$word%' AND column LIKE '%$word%' LIMIT $start, $per_page ";

$query_list = "SELECT * FROM table WHERE column LIKE '%$word%' AND column LIKE '%$word%' ";
$results_list = mysql_query($query_list) or die(mysql_error());
$results = mysql_query($query) or die(mysql_error());
$count = mysql_num_rows($results_list);
if($count >=1){
$search_output .="<hr />$count rezultats <br />";
while ($row = mysql_fetch_array($results)){
$search_output .= " blablablabla";
if($pages >= 1 && $page <= $pages){
for ($x=1; $x<=$pages; $x++){
$page_numerotation .= ($x == $page) ? '<strong>' . $x . '</strong> ' : '<a href="?page=' .$x. '"> ' . $x . '</a> ';

$search_output = "<hr /> 0 rezultats. <hr /><br />";


and if can anyone help me with an easy pagination
1 to 10 page links than use <back and next> or something like that...

ty in advance

02-23-2012, 05:13 PM
I don't know why you have a $query_list in here at all. Since this one is not limited like the count or the dataset, basing your count on this will not provide an accurate representation of the data at hand. Everything should come from the $query query you have.
As for your second, where does $word come from? The behaviour you are describing is that it matches all records indicating your search criteria is %% and $word is undefined. If you paginate with a filter, you have to provide that filter as a part of the request.

02-23-2012, 05:26 PM
$query_list is there because (I don't know why) when I found more than 20 results... the count was exact 20 (the number of results/page). So I "decide" to make a new query just for list the results, because the count id query just doesn't to hes work :D

and for the query of $word... yes... is query to match 2 words... and they are defined... before the connect line. this isn't my problem....

the code works fine... less side presented on the firs post...

02-23-2012, 05:46 PM
The $query_list is not required. If its for a count, use what you pulled from the COUNT() call.

Show where $word is defined.

02-23-2012, 06:13 PM
I have one but... it works only to show how many results will be divided/page...
but what about my problems....?!?

02-23-2012, 06:17 PM
I have one but... it works only to show how many results will be divided/page...
but what about my problems....?!?

Show where $word is defined.

02-24-2012, 09:22 AM
i used another code... and I have same problems...
I used $word to change the name here
there are 2 $
$word1 and $word2.
its a search form using 2 dropdown menus.
column1 = colors: red, blue, yellow
column2 = size: S, M, L

when user select from dropdown red and M

i have

$color = $_GET['color'];
$size = $_GET['size'];

so the query is something like this

SELECT * FROM table WHERE color LIKE '%$color%' AND size LIKE '%$size%'

I used this because I`m not familiar with arrays and stuff :(

what could be the problems?

02-24-2012, 11:00 PM
Not sure how I overlooked this one today.
How are you building your pagination links? The first block of code you have doesn't pass the $word anywhere within it, only the page represented by $x. As mentioned, you need to provide this query on every request.

02-25-2012, 12:26 AM
At a quick glance I noticed the only way that would show your 0 results output is if it can't connect to the database. You have to make an else statement inside the last bracket.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum