rpjd Posted May 4, 2011 Share Posted May 4, 2011 I want to create a sort trigger, group by and order by on a table after insert. Should the trigger be of this nature create trigger triggername after insert on tablename for each row begin insert into table (column1, column2 ) values ( value1, value2) group by column1 order by column1 end; Quote Link to comment https://forums.phpfreaks.com/topic/235550-sort-trigger/ Share on other sites More sharing options...
Drummin Posted May 4, 2011 Share Posted May 4, 2011 The GROUP BY and ORDER BY would be used when you query the array. So you insert the values into your DB with one action(form etc) then to view you query the DB and you can sort the results any way you wish. Using a simple $_GET you can change the order the query is sorted. Something like this. $id=$_GET['id']; //I assume you're calling the table with some value IF ($_GET['groupby'])} $sortby="GROUP BY $_GET[groupby]"; } IF ($_GET['orderby'])} $sortby="ORDER BY $_GET[orderby]"; } $showtable = mysql_query("SELECT * FROM mytable WHERE ID='$id' $sortby"); WHILE($shwtable = mysql_fetch_array($showtable)){ echo "Add table showing here"; } Quote Link to comment https://forums.phpfreaks.com/topic/235550-sort-trigger/#findComment-1210598 Share on other sites More sharing options...
rpjd Posted May 4, 2011 Author Share Posted May 4, 2011 I thought a table could be sorted after an insert using a trigger. A table like this (unsorted) File1 text changed File3 text changed File4 text changed File1 text changed File2 text changed File5 text changed File2 text changed File3 text changed I want to display grouped by and ordered by File like so in tables Table1 File1 text changed File1 text changed Table2 File2 text changed File2 text changed Table3 File3 text changed File3 text changed Table4 File4 text changed Table5 File5 text changed trying to figure out what queries I need to do this besides select (*) from table group by File order by File and how to nest them. Other queries in conjunction I had in mind were select count(distinct File) from table and select count(changes) from table group by File order by File When printing the result of the first query how to use either or both of the other query results? Any help greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/235550-sort-trigger/#findComment-1210630 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.