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
52
Other forums
php form help
Hey,
I use a control file to set my meta tags and titles
Here's an example
Code: &a
. and .. appearing instead of pictures
First of all, thanks very much for providing this forum. It is very much appreciated!
My son
problem when runing a funciton
I am trying to connect to database using a funciton in a functions.php
<?php
funct
How to display objects in a row
I have 7 codes that i want to display in a row one next to another.
The first is {$ads->ad
Empty text file when there is over XXXX lines of text.
define("RANDOM_FILE","/public_html/random.txt");
$randomEntry = "
IF Statement & Two Tables With Different Echoes
I'm retrieving two tables in a single query using UNION ALL, like so:
Code: $query = "SE
Word filter problem
Hello,
im trying to make a filter for words inputted in to my website but i want to store the
help with contest script
I would like to code a contest script to my site but i don't know how. Could someone just give me pu
listcube issue
Hi
I have a virtual cube ZREMOTE. I use Tcode "listcube" to retrieve contents. I use of the
Check premium expire
Hi,
I am making a simple file hosting site and want to check if users premium subscriptions h