Forum Moderators: coopster
The dropdown
<form action=$_SERVER['PHP_SELF'] name=limitnews>
<select name="limit_option" onchange="document.limitnews.submit();return false;"> <option value=5> 5 News </option><option value=10> 10 News </option> . . . . </select>
</form>
The $whatever can be retrieved from
$_REQUEST['limit_option']
I hope this helps, it might need some modifications.
I've tried
<?php
//code to show number of news items.
if ($_SERVER['REQUEST_METHOD']!= 'POST')
{
$rowsPerPage = $_post['choice'];
echo
'<form name="choice" method="post" action="post">
<select name="choice">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<input type="submit" name="choice" value="submit"/>
</form>';}?>
Would it work?
I'll try your idea later tonight at home...
<?php
//code to show number of news items.
echo
'<form action=$_SERVER['PHP_SELF'] name=limitnews>
<select name="limit_option" onchange="document.limitnews.submit();return false;">
<option value=1>1 News</option>
<option value=2>2 News</option>
..
..
..
<option value=10>10 News</option>
</select>
</form>';
?>
Do I set the variable in the display code like this?
// how many rows to show per page
$rowsPerPage = 'limitnews';
instead of
// how many rows to show per page
$rowsPerPage = x;
For those interested, this is my drop down form
<?php
//code to show number of news items.
?>
<form action=all_news.php name='limitnews'>;
<select name="limit_option" onchange="document.limitnews.submit();return false;">
<option value=1>1 News</option>
..
..
..
<option value=10>10 News</option>
</select>
</form>
And my 'display number of' code is this...
include 'display_number.php';
// how many rows to show per page
$rowsPerPage = $_REQUEST['limit_option'];
When I look at my news page, I get a db query error because the value for $rowsPerPage has not been set by the drop down. What's the easiest way to have this variable set as 4 for example, becasue setting it as $rowsPerPage=4 or whatever doesn't work? Is this because setting it, then looking for a drop down change causes it to revert to nothing?
I get a db query error because the value for $rowsPerPage has not been set by the drop down.
Is this happening when you submit the form? Or before submitting the form.
If it is before submitting the form, it could be because you are just including "include 'display_number.php';" even when the form is not submitted leading the $rowsPerPage & $_REQUEST['limit_option'] have empty values.
The code in display_number should be used after checking that the form is indeed submitted:
if ($_REQUEST['limit_option']) {
// Proceed with the query and other lines
}
Had a sniff about and I'm using this..
if(!isset($_REQUEST["limit_option"])) $rowsPerPage = "4";
else $rowsPerPage = $_REQUEST["limit_option"];
This works fine.
What was your warning about not trusting $rowsPerPage = $_REQUEST["limit_option"];?
I'm still learning!