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
image upload script not working with png
The basic process of this php code is to take the submitted file, convert it to a small JPG thumbnai
Return X values where an ID number doesnt matter
Well as for subject heading, thats the best i could think of.
Currently im having a problem w
http to https
Hi,
Is there any specific method/condition to move an http:// page to https:// ?
multiple recipients + dbuser mail recall
Hello,
I am building a php login script.
When the user registers the script will send
Lining up columns nicely.
Hello everyone, I'm having problems with making columns line up properly. Here is my code:
Problems with adding a link to one position in a 'foreach' loop, please help
Hello!
Iam pretty new to programming and I wanna create a table with users from an array. It
multipart emiail forms
Hi All,
I am new to the boards and I've been working on a form (which is rather massive, imo
Vertical Alligning - Not working in 1 cell?
<?php
echo "<table id="valign" width="60%" style=
How to sum these output values
Hi
I need sum the month totals
SELECT region_name, area_name
,SUM (CASE WHEN S
Calander Basic Spript help
hi, just starting out with PHP and have the following script:
<?php
//This gets t