How to submit a form to the same page?


Posted on 16th Feb 2014 07:03 pm by admin

I have a table containing information about books in my library and this table has the following columns: id, title, category. What I want to do is to make a form that will allow me to sort these books according to one of these fields, its just like in you tube when you want to sort videos by date added, relevance, view count etc..

Both the form and the php code are in "view_books.php"

Here is my form:

Code: <form method="POST" action="view_books.php">

Sort by:

<select size="1" name="sort">

<option> id </option>

<option> category </option>

<option> Date Added </option>

</select>

<input type="submit" value="Go!">

</form>

Here is my php code to sort the books in a table:

Code: $query = mysql_query ("SELECT * FROM books ORDER BY id asc ") or die (mysql_error());

?>

<table width="76%" border="0" align="center" >

<?

while($rows = mysql_fetch_array( $query ))
{

?>

<tr>

<td> <font color="#696969" size=2> <?php echo $rows['id']; ?> </font></td>
<td> <font color="#696969" size=2> <?php echo $rows['title']; ?> </font></td>
<td> <font color="#696969" size=2> <?php echo $rows['category']; ?> </font></td>

</tr>

<?

}

?>

</table>

Please apply the changes in my code so that it can perform the required function.

Thanks, any help would be appreciated.

No comments posted yet

Your Answer:

Login to answer
239 Like 52 Dislike
Previous forums Next forums
Other forums

Login script (probably a simple error)
dbConfig.php
Code: <?
// Replace the variable values below
// with your specific dat

getting Vars to pass to next page.
Hello all,
I have a confusing situation on my hands, i am a member of a gaming community and we

Trouble verifying database password
Thankyou to everyone who responded to my last post (I can't find the posting, it has been buried). <

PL/SQL: ORA-00947: not enough values error message
Hi all i am getting Error(25,63): PL/SQL: ORA-00947: not enough values error message when executing

matching numbers inside ( )
I know I can match numbers by just [0-9]+, so I thought matching numbers inside ( ) would be somethi

Not capturing all the information we require in the form.......
Hi Guys,

I was wondering if you would share some more of your knowledge today, I'm hoping it

Can php detect connection speed and thereafter swap out elements?
No code to post, lads, yet. Just looking for a yay or nay at this stage:

Can a php script be

Hi, explode and strstr.
Hi, I seem to be confused about the strstr function, eg. i have a string like:
"a.b.c.d.e.f&

PHP mail() returns true but doesn't work
First off I apologize if this is a newbie question, and I generally don't like asking questions that

Curly Bracket Delimeters.
I'd always believed that the starting and ending delimeters in preg_ functions had to be the same ch

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash