FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free 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;
              }
Related topics
HTML tables with irregular rows and/or columns
Why I think iTunes is horrible
Joomla - frontpage 2 columns help!
Page columns: tables or no tables?
3 columns using div and css
Css- 2 equal columns in Explorer
height 100% columns, fluid and only with CSS
CSS and centered columns
Sorting memory issue???
NEW DOMAIN - Best Site on Science!!!
Best filemanager?
Sorting result MySql
Separating equally ranked ranges in excel
Equal Columns in CSS
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

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