View Full Version : Strange question
tvollmer
08-24-2002, 07:24 AM
I have a table of data that I have output to HTML in my PHP script.
Each of the columns on the table have an image for a caption.
What I want to be able to do is to click on any of the column header images and then have the PHP script sort all of the columns in the table by ascending or descending (toggles when you click on the image).
Is this a hard thing to do?
If it is too complicated, all i really need to know is how to click on an image and send specific data back the the php file.
I hope I am making sense! :)
Todd
Spookster
08-24-2002, 07:44 AM
That makes senses. Is the data being pulled from a database?
tvollmer
08-24-2002, 07:52 AM
Yes,
basicaly what the script does right now is open a database, takes the data from one of the tables and outputs it to the browser using an html <table>.
I know i can sort the entire table by a specific column by putting an ORDER BY statement into the query.
I just need to know how to click on a column header to sort by that column.
Todd
Spookster
08-24-2002, 08:02 AM
For your query you can change the field that you are ordering by to a variable. Then in the linked image just pass the name of the column as the field to order by to the query.
sql = "SELECT * FROM tablename ORDER BY '$field' DESC";
<a href="thepage.php?field=columnnametoorderby"><img src="foo.gif"></a>
tvollmer
08-24-2002, 08:20 AM
Seems to work, but in a strange manner, lemme get back to you after a few tests.
Thanks
Todd
tvollmer
08-24-2002, 08:47 AM
Ok the code you gave me works.
Now when I click on a header image for each column, it sorts that column with DESC.
How can I make it so that if you click on the image AGAIN, it toggles the sort to be ASC?
Todd
Spookster
08-24-2002, 09:33 AM
Hmmmm. What you could do for that is dynamically change the link each time
<a href="thepage.php?field=columnnametoorderby&order=
<?php
if($order == "DESC")
$order = "ASC";
else
$order = "DESC";
echo $order;
?>
"><img src="foo.gif"></a>
and just set the ORDER value of your query to the $order variable.
tvollmer
08-24-2002, 08:31 PM
Almost got it, but the code you gave me does not want to work in my script.
Here is a sample snippet from my code where this feature would be used:
(This is a snippet of code for displaying the column header image)
print "<TD align=\"center\" bgcolor=\"#456281\">";
print "<a href=\"display_trade_skills.php?field=Baking\">";
print "<img border=\"0\" src=\"http://www.foo.com/Images/baking.gif\" width=\"75\" height=\"20\"></a></TD>";
Could you please show me how the code would be used in this example?
Todd
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.