Forum Moderators: coopster
I have a line of code to define how many records should be returned from database to be displayed to a webpage like this:
define(SHOWMAX, 10);
If I put on the top of the page a select list element to allow the user to select a different number of records to use to navigate throughtout the whole number of recordsets, how should I pass the value of that select list so that by selecting a different value the number of records per page should be adjusted to reflect what the user selected?,
NOTE: I am not hittig a button for that purpose, only selecting a different value should accomplish that goal
Regards
There is a great little intro to AJAX here: [news.php.net...]
Read it well and try to implement it. If you need further assistance, the Javascript and AJAX forum might be of more help to you.
The as you said I put a script in the background to check whether the submit button was submitted or not and define a query consequently
However, I must be honest, writing functions is my weakest point.
I defined the function as follows:
function nr_of_records()
{
// It retrieves the number of records indicated in the select list box.
if(!array_key_exists('nr_of_records',$_GET))
{
$query = "SELECT expense_id, date, DAYNAME(date), amount, expense_reason, payment_means, location FROM expenses ORDER BY date ASC LIMIT $start_row_number, ".MAXSHOW;
}
elseif(array_key_exists('nr_of_records', $_GET))
{
$selectRecords = strip_tags(trim($_GET['selectRecords'])));
$query = "SELECT expense_id, date, DAYNAME(date), amount, expense_reason, payment_means, location FROM expenses ORDER BY date ASC LIMIT $start_row_number, $selectRecords ";
}
return $query;
}
// the next line follows immediately the function.
$result = mysqli_query($connection, $query) or die(mysql_error($connection));
$start_row_number was defined before this function as
$start_row_number = $current_page*MAXSHOW;
WHEN I run the script I get the following error:
Undefined variable: query in C:\htdocs\MySQL_queries\all_expenses.php on line 80
Warning: mysqli_query() [function.mysqli-query]: Empty query in C:\htdocs\MySQL_queries\all_expenses.php on line 80
Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in C:\htdocs\MySQL_queries\all_expenses.php on line 80
I thought $query was received from the function but this is not the case.
Any help?