Jump to content

sort trigger


rpjd

Recommended Posts

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;

 

 

Link to comment
Share on other sites

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";
}  

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.