Grouping Results

Results 1 to 3 of 3

Thread: Grouping Results

  1. #1
    Jason Barnham Guest

    Default Grouping Results

    Hi there,<BR><BR>I have a DB with 4 important fields.<BR><BR>I have RegionID (number)<BR>ServicesID (number)<BR>LinkID (number)<BR>and Desc (which surprisingly enough is a description of the service)<BR><BR>The User is allowed to select either a service, a region or Both. My problem is that if they select a specific service I can pull out all the results but I need to group them into regions with a region heading on top (displayed only once). Obviously at the moment the results are pulled as they are found scattering all the regions and making the results very disorganised. Can anyone tell me how I can achieve the grouping I require.<BR>Thanks in Advance<BR>Jason Barnham

  2. #2
    Rhys Guest

    Default RE: Grouping Results

    There are a few ways to do this. Either client side or server side. <BR>If you want to do it server side -<BR>at the moment if they are selecting a service then you are doing<BR>a SELECT * FROM table WHERE ServicesID = x <BR>you can add ORDER BY RegionID and it will order the results by the RegionID - and will group RegionIDs together if they are of the same value.<BR><BR>This will work if being in the same region means that they have the same RegionID - otherwise you need another set of logic to group the regions. <BR><BR>To get the Region name you will need to query the region table seperately or do a join. If you do a join in the above select statement then you will get the region name and the results will be grouped by this and in order of the RegionID (if the order by is as above) or if you order by the region name in the joined SQL statement then it will be alphabetical.<BR><BR>Now to display the region name and then write rows of the ServiceId, LinkID and Desc underneath the Region heading - I would use an array. (If you need to display servicename and Linkname then you will have to query these tables aswell either seperately or with a join.)<BR><BR>To make it simple just write a table from the select statement above - if you dont want to duplicate the regionname on each row then you need to use a logic on the array.<BR>Each row you write you can put the regionname element into a local variable - then when the next row is written compare this variable to the next regionname element - if they are the same (ie same region ) then don&#039t write the regionname - if they are diferent then do.<BR>You would have to apply another logic to have the regionname above the rows- ie if the regioname element is different to the local variable then write the regionname then go to the next row and write the rest of the info - then goto the next row and compare the regioname element again with the local variable -and so on .<BR>Basically if the regionname is new (ie its different from the local variable holding the last value) then write the name - and the rest of the row blank -- then on teh next row write the rest of the info - and so on.<BR><BR>There are a few layers of logic here anyway - so have a go -<BR>try and deal with one at a time.<BR><BR>all the best<BR><BR>

  3. #3
    Jason Barnham Guest

    Default RE: THANK YOU

    Thank you very much, you have given me a lot more insight. Thanks for taking the time to answer my problem - Much appreciated. Regards - Jason

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts