Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8010301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:41:45+00:00 2026-06-04T18:41:45+00:00

hi i have set up a php based form submission method for sorting rows

  • 0

hi i have set up a php based form submission method for sorting rows per page in a select drop down menu, it is working fine i get to sort the rows according to value selected, but my problem is when a value is selected for sort it doesn’t shows up in form selected field as whats currently selected.

what i mean to say is that when a value is selected in drop down menu for sorting rows it should show up as current in select-box as default value, and if nothing is selected then default row value should show up as current.

please see here here at the sorting method, it shows current(10) as default rows and when a value is selected it becomes as current on page reloads after querying database.

here is my html code for form field:

<form action="is-test.php" method="get">
<select name="rpp" onchange="this.form.submit()">
<option selected value="">show</option><!-- i want default & current selected value here -->
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
</select>
</form>   

and php code for this sorting is:

$rowsperpage = '';
if (isset($_GET['rpp'])&& is_numeric($_GET['rpp'])) {
$rowsperpage = (int) mysql_real_escape_string($_GET['rpp']);
}else{
$rowsperpage='5';
} 

and mysql query for this is:

$sql2 = "SELECT * FROM $tablename ORDER BY $orderby $sortby LIMIT $rowsperpage OFFSET $offset";

please sugest me a way to set selected value as current value.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T18:41:46+00:00Added an answer on June 4, 2026 at 6:41 pm

    In your <option> tags, you should performed checking like this:

    <option value="10" <?php if ($rowsperpage == 10) echo 'selected="selected"' ?>>10</option>
    <option value="20" <?php if ($rowsperpage == 20) echo 'selected="selected"' ?>>20</option>
    <option value="30" <?php if ($rowsperpage == 30) echo 'selected="selected"' ?>>30</option>
    

    So if you select 20, it will displayed as the current value of the <select>

    <option value="10">10</option>
    <option value="20" selected="selected">20</option>
    <option value="30">30</option>
    

    To make things simpler, just use for loop like this:

    for ($i = 10; $i <= 30; $i+= 10) {
      echo "<option value=\"$i\" ".($rowsperpage == $i ? 'selected="selected"' : '').">$i</option>";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP-based sorting method with a drop-down menu to sort rows. It
I have the following dropdown box <form name=myform method=POST ACTION=songs.php> Select Category: <select id=sel
I have set the form decorators in this way: <?php $this->setElementDecorators(array( 'Label', array(array('labelTd' =>
I have a form on my page which contains two select dropdowns. The first
I have a page which has a drop list inside a form. The drop
I have a php page to capture sales orders. it has a dependant drop
I am developing w php web site. Here I have set a php cookie
I have set up a php script to receive url data like this: http://giffgaff.liamwli.co.uk/?name=liamwli
I have a set of .php files in a folder, I want to add
I have to set some routing rules in my php application, and they should

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.