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

PHP Upload issue
Hi guys,

I have stumble across an interesting issue with my script and is doing my head in.

$_POST
Hi, I have 2 seperate php files, and i want my $_POSt["fname"] To go into both of them, Fo

mysql_query returning boolean instead of mysql ressource
Hi,

I seem to have a weird issue with the php command mysql_query. I pass 2 arguments the que

pagination - need help on passing of search query.
Hi, i have been trying for days but couldn't get this sorted out. Would like some professional help

column name cancatenation within PL/SQL
I have a PLSQL store procedure, and the following statement is part of a subquery
fname||lnam

date("now") prints out wrong date ?
Hi Guys
Anyone know why and how I can fix it ?

Table trouble
i have been reading the forum for a few weeks and decided to join. i like the format and the advice

Why is this function returning a false value when it shouldn't be??
This is in an include file. I want it to check a value in an html form and see if it's just white s

mail()
Hi all. I have a problem with emails. I am trying to set up a mail system where customers can subscr

creating a 1 to 100 in a table
hi guys I am a newb in php need some help.

I have a table with 1 column and 100 rows and in

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