close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Grouping results of a recordset

Thread began 11/27/2009 3:21 am by Banksie | Last modified 6/14/2013 3:46 pm by Paul | 916 views | 2 replies |

Banksie

Grouping results of a recordset

I'm using DA2.0.6 developing a php / MySQL site and have a recordset that pulls a list of locations from a clients list of places where they have depots:

SELECT DISTINCT tbldepots.depotName
FROM tbldepots
ORDER BY tbldepots.depotName

but now want to group and display those records in alphabetical blocks under separate tabs (in a spry tabbed panel section of the page) so all "A*" locations are under the A tab, Bs under B etc.

Currently the repeat region on the page contains all of the records A-Z in a standard do...while loop:

<?php do { ?>
<li><?php echo $row_rsDepots['depotName']; ?></li>
<?php } while ($row_rsDepots = mysql_fetch_assoc($rsDepots)); ?>

I've tried experimenting with strpos etc:

if (strpos($row_rsDepots['depotName'], "a") ===0) {
echo $row_rsDepots['depotName']; }

But am not quite getting it how I think it should be! Am I missing something so obvious at the moment? (can't see the wood for the trees syndrome!!)

Any ideas as to how I can do this without having to run separate recordsets with a WHERE clause to pick out the individual letters?

Sign in to reply to this post

Jason ByrnesWebAssist

To group the results in the manner you are describing, you have to first set a variable to be blank, compare it against the grouping, then reset it.


The following is a code example that will create alphabetical headings for the depot names:

php:
<?php $firstLetter "";?>

<?php 
do { ?>
  <?php 
     
if($firstLetter != substr($row_rsDepots['depotName'], 01)) {       
       echo(
"<b>".substr($row_rsDepots['depotName'], 01)."</b><br>");
       
$firstLetter substr($row_rsDepots['depotName'], 01);
     }
  
?>
  <?php echo $row_rsDepots['depotName']; ?><br>  
<?php } while ($row_rsDepots mysql_fetch_assoc($row_rsDepots)); ?>
Sign in to reply to this post

Paul

This post has been deleted.

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...