close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues


SQL query question

Thread began 7/30/2014 5:43 am by iainmacdonald331081 | Last modified 7/31/2014 1:11 pm by Jason Byrnes | 1992 views | 7 replies |


SQL query question

I have a table of lodges and table of scores:

LodgeID (PK)


For any given lodge, I have a page where the results can be viewed, with a list of all the categories.

I would like it only to display the categories where there are any scores (votes) in that category.

So I have a query WADAlodges on a page which refers to the lodges and scores tables for each category:

SELECT * FROM lodges INNER JOIN countries ON lodges.CountryID = countries.CountryID INNER JOIN scores ON lodges.LodgeID = scores.LodgeID WHERE lodges.LodgeID = %s OR ( -1= %s AND lodges.LodgeID= %s)

So it might return, for example,

LodgeID, Question
123, 1
123, 2
123, 3

And I have some code to only display the text for each category, e.g.

<?php if ($row_WADAlodges['value']=="Yes" AND $row_WADAlodges['2015_Awards_Participant']=="Yes" AND $row_WADAlodges['Question']=="1"){ ?>

<?php if ($row_WADAlodges['value']=="Yes" AND $row_WADAlodges['2015_Awards_Participant']=="Yes" AND $row_WADAlodges['Question']=="2"){ ?>

<?php if ($row_WADAlodges['value']=="Yes" AND $row_WADAlodges['2015_Awards_Participant']=="Yes" AND $row_WADAlodges['Question']=="3"){ ?>


But that only works for the first record in the query - how can I get it to work for other records for other scores?

Hope that makes sense, as I'm not sure I've explained it very well.

I have attached a copy of the page.


Sign in to reply to this post

Jason ByrnesWebAssist

you need to add a repeat region to repeat the records from the WADAlodges recordset.

there is no repeat region on your page for that recordset.

Sign in to reply to this post


Thanks Jason - I didn't think of that as I'm not actually displaying anything there, just showing a link to another page with the results for each category / question.

Sign in to reply to this post

Jason ByrnesWebAssist

but your using the recordset to show the link, so need to loop through it to show all links.

Sign in to reply to this post


Hi Jason - I've been looking at this some more, and realised it would make sense to leverage some of the fields in the tables to display the relevant parts, so for example the Category field to display the category etc. That way, as the recordset is being looped, I only need that bit of code once.

So I have it working with the loop, but as its not a one to many relationship, its showing multiple instances. For example, if a lodge has two votes in the Best Value category, there link to the Best Value results page appears twice, when I only need it to show once.

I'm also not sure why its displaying %20 between the words.

To look at what its currently doing look here:

Login with


Click on 2015 Nominees - Namibia near the bottom on the left hand side.

Click on Handprint Property 102.

It has two votes each for Best Value and Best New, and one for Best Community.

And its showing the link to the Best Value and Best New results pages twice each, when it just needs to be once.

Sign in to reply to this post

Jason ByrnesWebAssist

you needded to add a group by clause. I added:

GROUP BY categoriesFull.CategoryID

to the recordset.

the text was showing %20 because you where using rawurlencode():
<?php echo(rawurlencode($row_WADAlodges['Category'])); ?>

i changed that to:

<?php echo($row_WADAlodges['Category']); ?>

Sign in to reply to this post


Thanks Jason.

Sign in to reply to this post

Jason ByrnesWebAssist

you're welcome.

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





Ease of use


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