close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

SQL query help

Thread began 3/25/2014 8:35 am by iainmacdonald331081 | Last modified 3/26/2014 7:41 am by Jason Byrnes | 644 views | 5 replies |

iainmacdonald331081

SQL query help

I currently have the following structure:

table: lodges
LodgeID (PK)
Lodge
LodgeDetails
etc

table: nominations
NominationID (PK)
Nomination
Category
Year
LodgeID
etc

table: scores
ScoreID (PK)
Score
ScoreYear
LodgeID
etc

table: trade_users
UserID (PK)
LodgeID
User
etc

And I have a page which lists any lodges which have either a 2015 Nomination or a 2015 Score (i.e. nominations.Year = 2015 OR scores.Year = 2015) for the currently logged in user using the following SQL:

SELECT DISTINCT lodges.LodgeID, Lodge, banner_image_new, Country, banner_image_new_title, photo_one, photo_one_title, Summary_2013, 2014_Nominee, GSG2014, Year, ScoreYear, Nominee, Finalist, HighlyCommended, RunnerUp, Winner, Category, 2015_Paid, 2015_Awards_Participant FROM lodges LEFT JOIN nominations ON lodges.LodgeID = nominations.LodgeID LEFT JOIN scores ON lodges.LodgeID = scores.LodgeID WHERE lodges.UserID = %s AND (Year = 2015 OR ScoreYear = 2015) ORDER BY Lodge ASC

Which works, but lists results:

Lodge A - Category 1
Lodge A Details

Lodge A - Category 2
Lodge A Details

Lodge A - Category 3
Lodge A Details

Lodge B - Category 1
Lodge B Details

etc

How could I change that to list the results in this way:

Lodge A
Category1, Category2, Category3
Lodge A Details

Lodge B
Category 2, Category 5
Lodge B Details

etc

Sign in to reply to this post

Jason ByrnesWebAssist

instead of using a joined query for this, i would use a nested recordset to return the categories:


http://www.webassist.com/tutorials/Display-nested-recordsets

Sign in to reply to this post

iainmacdonald331081

Thanks Jason - sorry if I'm going blind, but I don't see the Preset Manager it mentions right at the start:

In Dreamweaver, click WebAssist > Preset Manager.

I assume I can try to follow along from the step where record sets are added, where menu_categories are the equivalent of lodges, and menu_items are the equivalent of nominations or scores.

Sign in to reply to this post

Jason ByrnesWebAssist

the preset manager should near the end of the list if you have data bridge installed.


"I assume I can try to follow along from the step where record sets are added, where menu_categories are the equivalent of lodges, and menu_items are the equivalent of nominations or scores."

yes, that is correct.

Sign in to reply to this post

iainmacdonald331081

Thanks Jason - I have managed to get this all working now. I did go wrong, but fixed it when I had the run time value of LodgeID in the nominations recordset set to:

$row_WADAlodges['LodgeID'] rather than $_GET['LodgeID']

I thought it was about to get complicated by the either or of the nominations and scores, but realised I just needed to keep the joins in the original Lodges query to filter the correct lodges, and the nominations query to list the nomination categories.

Sign in to reply to this post

Jason ByrnesWebAssist

glad to hear you have it working.

Sign in to reply to this post

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...