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 Multiples of 2, Show posts...not working (wordpress)
I have been using this code to show div.example with 6 li columns inside it, each li is a post with

remove trailing slash from array
I have the following array which contains trailing slashes I need to remove. What is the best way to

adding up might be solved tell us cheers.
i think i finally solved this anybody.

last time i was getting the wrong results.

Code

newbie question
Hi out thereIm totaly new in this forum and to .net and vb so here is a totaly newbie question.I wan

How can I uploading Transactional Data from Legacy to New SAP system
Hell Gurus,

I am overwhelmed with questions on how to migrate huge volume of Sales Orders

quick question about System Change Number(SCN) in FlashBack Query topic
i know tht we can get the SCN of the database using flashback concept as follows

SQL>

Trying to add functions to table
I have this list of characters and I'm trying to figure out what I have to do to put the results of

PHP, jAVASCRIPT setting input values, why isn't it working?
Hi:

I am calling this javascript:
<script language="javascript">

INSERT data problem!
After having an string with apostrophes ', double quotes " or any other special characters, suc

Deleting a record php
Attempting to setup delete a record page. The below code I put together doesn't seem to work.

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