My database holds a table with the names of 30 users. I have the following html form which is a search form:
<form method="POST" name="go" action="search_form_all.php" >
<input name="value" type="text" id="search_form_1" size="65" />
<input type="submit" value="" name="submit" />
</form>
Then usign the following php script, the form as a result displays all names from my database:
if(isset($_POST['value'])== true && empty($_POST['value']) == false){
$value = mysql_real_escape_string($_POST['value']);
$name_and_surname = explode(" ", "$value ");
$name = $name_and_surname[0];
$surname = $name_and_surname[1];
$query = mysql_query(" SELECT `name`, `surname`, `email`, `user_id` FROM users WHERE (surname LIKE '$name%' AND name LIKE '$surname%') OR (surname LIKE '$surname%' AND name LIKE '$name%') LIMIT 10 ");
while($run = mysql_fetch_array($query)){
$name = $run['name'];
echo" $name ";
}
by executing the above code, I get the first 10 names (because in my sql query have limit 10). All I want is to have a button that when the user press it to extract the rest 10 names and then the rest 10 until all 30 names extracted. How can I do this?
the sql LIMIT function can handle more than just one number, for example LIMIT 10, 20 will output the 10th to 20th result.
I'm sure you can figure out something with your form and posting to use that to your advantage
More info about the SQL LIMIT here: http://php.about.com/od/mysqlcommands/g/Limit_sql.htm
SELECT `name`, `surname`, `email`, `user_id`
FROM users
WHERE (surname LIKE '$name%' AND name LIKE '$surname%')
OR (surname LIKE '$surname%' AND name LIKE '$name%')
LIMIT $offset, 10;
where offset can be 1,11,21 in your case
You can use a classy solution called PAGINATION in web lingo..It simply gets a chunk of data and prints out the links pointing to the next page..http://www.phpfreaks.com/tutorial/basic-pagination may help
You can use that value and manipulate according to your needs..For example you can use it in in your LIMIT Statement..