FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

sorting columns

 


woodenbrick
Hope someone can help me with this...
I have a table of chemicals, formulas etc. and I want to be able to sort it into ascending and descending order by clicking on the column header.
ncwdavid
IS that clicking on a column header in the database or in a little script you made that shows the data? Well if its in a little script the maybe put a link on the column header like this:
Code:
<a href="http://www.yourdomain.com/view.php?columnname=COLUMNNAME&order=DESC">HEADER NAME</a>


Then in the view.php file just have a sql query:
Code:

$order = $_GET['order'];
$column = $_GET['columnname'];
$order_query = mysql_query("SELECT * FROM TABLENAME ORDER BY $column $order");
 


That should do it but of course have a little "if()" statement where the link will be to change it from DESC to ASC when needed. That's all it should take.
woodenbrick
ok thanks very much david I've got the column ordering working nicely now. I got it to change between asc and desc with a session counter and a function for checking if the number is odd. Not sure if its the greatest way of doing it, but it works.

I wonder if you could take a quick look at this if you check back, its for making sure the data hasn't already been placed in the table, but at the moment its saying it is always duplicate data, even if it isn't.
Code:

//check if data is unique
              $check = mysql_query("SELECT * FROM `attacks` WHERE MATCH (Defender, date, time)
              AGAINST (+'$Defender +$date +$time' IN BOOLEAN MODE)") or die ('Some problem'.mysql_error());
              if (mysql_num_rows($check) > 0) {
              echo "Duplicate data";}
              else {
              mysql_query($insertData) or die ('Error inserting data '.mysql_error());}
              $A_XP = 0;
              }
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.