Too many results returned once I add another table

Too many results returned once I add another table

Currently on my results page when I leave the search fields blank it returns every row in my LINE table which it should. Right now there are only three rows and it returns all three. The search works for the other fields so there is no problem here.

Now, I have a second table of pictures that belong to the LINE table connected by a LINE_ID. There could be many pictures for each LINE so I went this route instead of just adding a picture column in the LINE table. Make sense?

My problem is that when I add the table and column to my query, instead of returning only three results with the pictures linked, I get 15 results returned. I have 5 rows currently in my PICTURES table, so it returns 5 rows for every LINE returned. Likewise, if I narrow the search so only one result should return. I get 5 results using the second query while using the original query the one proper result displays.

--------------------------Here is the original query that works correctly but doesn't contain the table/column needed to display my images. This returns all results as I would expect.

SELECT Line_Id, Line_Name, Line_Nickname, Start_Decade, End_Decade, Manufacturer, Size, Cat_1, Cat_2, Cat_3, Approved, Locked, Added_By, Line_TextFROM figure_linesORDER BY Line_Name DESC----------------------------------------------------Here is my modified query that gives my recordset the binding I need for the pictures. This returns all the results the above query does plus everything that has a Filename. Which I get, but I do not know how to go about being able to get the bindings for the pictures another way. I've tried messing with the WHERE statement and variables a bit to no avail.

a record will be returned for each picture which is the cause of the problem you are having, in your recordset output code, you need to add some hand coding to only show the figure_lines information once.

The idea of the code is this:

just before the recordset loop, create a variable that is empty:<?php $rsID = ""; ?>

around the code that will display the info from the figure_lines table add an if statement so it will only show if the $rsID is NOT equal to the current figure_lines.Line_Id

<?php if($rsID != $row_RecordsetName['Line_Id']) { ?>

<code to output the recordset info>

<?php } ?>

then set the $rsID to the current Line_Id:<?php $rsID = $row_RecordsetName['Line_Id']; ?>

I'd also like to be able to only have the picture row returned that has the thumbnail column marked. All suggestions are welcome. Thanks in advance.

same type of if statement, i dont know how your 'marking' the thumbnail column so cant really say exactly what to use in the if statement, but the idea is:<?php if($row_RecordsetName['Thumbnail'] == '1') {?>show images<?php } ?>

I did try INNER JOIN before but screwed it up. Need to work on DB sites more than once every year or more so I retain this stuff. And thanks for your explanation, it's helped make sense of it.

So I am returning only the correct results now and not every instance thanks to the INNER JOIN. But I am having issues getting only the thumbnail row to display. Below is the code that displays the image. The first set is unaltered, the second is what I thought you meant to happen. Obviously it's wrong but I don't know the correct answer. Sorry for being dense and thanks in advance!

OK, I stand corrected, can you provide more details on what the problem is? you dont really say what is happening with the code snippet you provided versus what you are expecting top have happen, there's not a lot on information for me to go on.

Please provide a detailed explanation of the problem. A link if you can would help along with a copy of the page in a zip archive so I can see the code in context.

Here is a link to the search page: figure_lines_Search.php(do a search for star wars in the top search form - it will return 2 results - both are for star wars but I only want 1 returned for the star wars row that has a 1 in the Thumbnail column)

Rate your experience or provide feedback on this page

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 Window

We were unable to retrieve the attached file

Post a question as

Email me with all replies to this thread

Title:

Public Message: (viewable by anyone reading this thread)(do not cut and paste code into this field unless necessary, attach copies of your pages so they can be opened in Dreamweaver for debugging)

Quote message in reply?

Private Message: (viewable only by you, the person you are replying to, and WebAssist employees)(only put truly private information in this area such as ftp details and phone numbers. Keep as much of your post public as possible)

These attachments are private (viewable only by you, the person you are replying to, and WebAssist employees)