PHP Query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
barlow1123
Forum Newbie
Posts: 1
Joined: Fri Nov 26, 2010 6:31 am

PHP Query

Post by barlow1123 »

hi,

im creating a very simple web shop for some practice... im connected to my database and showing the table fine, what i want now is to add a HTML button that when clicked sorts the table in order of price.

I can do this by directing and sorting the table on a new page, but i was wondering if it could be done on the same page (maybe with a function or something...)

Heres my code for printing the table...

<?php
$conn = pg_connect("host=************* port=**** dbname=******** user=******* password=*******");
$res = pg_query ($conn, "select * from CSGames");
echo "<table border='1'>";
echo "<th>Title</th><th>Description</th><th>Price (£)</th><th>Select</th>";
while ($a = pg_fetch_array ($res))
{
echo "<tr>";
echo "<td>" . $a["title"] . "</td>";
echo "<td>" . $a["description"]. "</td>";
echo "<td>" . $a["price"] . "</td>";
echo("<td><input type='checkbox' name='select' size='20'></td>");
}
?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP Query

Post by Celauran »

I suppose the easiest option would be to resubmit the query with ORDER BY price ASC attached. Leaving the form action blank or pointing it to the current page will reload the page.
Post Reply