PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Im trying to search a table and bring back paginated results .. Here is the code I have been playing with .. but have had no luck in gettin it to work ..
No errors .. When the page is viewed .. all the users in the table show .. the pagination works fine .. But when you search .. nothing seems to exicute .. the page reloads with all users still being displayed ..
I trying to have it display all records .. then after a search is exicuted have it only display the search results .. and paginate if needed ..
$sql = mysql_query("SELECT * FROM users WHERE (user_name LIKE('%$search%') OR first_name LIKE('%$search%')) ORDER BY first_name LIMIT $from, $max_results");
the % was missing before $seach, and also before the query, do something like
It seems when a search is performed .. the matching record comes to the top of the list .. but all the other records show .. how do you have it so only the search results show ..
The search works to a certain extent .. If I have the max records set to 2 .. and I perfom a search .. and there is 1 match .. it displays the 1 match .. but also has links to page 1,2,3 .. etc ..
If there are 2 records that match .. it shows both but also has the page links ..
What needs to change so if there is 1 match .. have it display the 1 match with page 1 showing .. but not links to page 2,3,4 etc .. but if there is 3 matches .. then have it show 2 on page one then a link to page 2 with the 3rd match ..
Basically, as long as the form is submitted with the search field filled in, it will perform the search, other than that should display all results until form is submitted
Thanks .. that works now .. But after a search it stills paginates all the records .. I want it so after you submit a search .. it only paginates the records that match the search query .. and doesnt display the rest ..
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM users WHERE (user_name LIKE('%$search%') OR first_name LIKE('%$search%'))"),0);
?
Im not sure how to parse the search variable thru the pages ?