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

strtotime issue
Hey all,

I'm playing around with some code, and basically the idea is:

Person changes

ImageCreate()
When I create an image and add text to it I want my text to be replaced with a PNG image, because th

ctype() validation - allowing illegal characters
Hello,
I use ctype() to filter and validate a user form. However, I am trying to allow certain c

Undefined offset when using a flat file with pipe symbols
Hi, I've got a flat file/text file which I'm currently using as a member database for my site (not a

MySQL query problem
When I try to run the following piece of code, I get this error:
QuoteWarning: mysql_query(): sup

dynamic table with forms
I have a table that is populated with mysql data and in teh first column there is a raido button tha

PHP and SMS
Hi all forum members. I am new here and am unsure what category shoild I post this in.
Moderator

Pipe email to PHP - get mail adress from MySQL - send?
Hi all,

this is the challenge:

1) Our faculty at the college where I'm employed includ

Troubles with a spider class
I am building a spider that will crawl through random whitepages (eg. anywho.com, switchboard.com, w

Add 5 to a variable when a button is clicked, and re-run a for loop
So I'm making a feedback sort of section on a website with MySQL and PHP, I've gotten the script to

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