close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Too many results returned once I add another table

Thread began 6/07/2011 1:33 pm by Jared Lui | Last modified 6/15/2011 8:34 am by Jason Byrnes | 3440 views | 18 replies |

Jared Lui

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_Text
FROM figure_lines
ORDER 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.

SELECT figure_lines.Line_Id, Line_Name, Line_Nickname, Start_Decade, End_Decade, Manufacturer, Size, Cat_1, Cat_2, Cat_3, figure_lines.Approved, Locked, figure_lines.Added_By, Line_Text, picture.Filename
FROM figure_lines, picture
ORDER BY Line_Name DESC
--------------------------

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.

Sign in to reply to this post

Jason ByrnesWebAssist

For 1, your query is not quite right, it should use a join syntax:


SELECT figure_lines.Line_Id, Line_Name, Line_Nickname, Start_Decade, End_Decade, Manufacturer, Size, Cat_1, Cat_2, Cat_3, figure_lines.Approved, Locked, figure_lines.Added_By, Line_Text, picture.Filename
FROM figure_lines
INNER JOIN picture ON figure_lines.Line_Id = picture_lines.Line_Id
ORDER BY Line_Name DESC

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 } ?>

Sign in to reply to this post

Jared Lui

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!

Oh, and the data in the Thumbnail column is 1 and 0.

-----------------------------
<div class="WADAResultThumbArea"><a href="figure_lines_Detail.php?Line_Id=<?php echo(rawurlencode($row_WADAfigure_lines['Line_Id'])); ?>" title="<?php echo $row_WADAfigure_lines["Line_Name"]; ?>"><img class="WADAResultThumb" border="0" src="images/TESTIMAGES/<?php echo $row_WADAfigure_lines['Filename']; ?>" /></a></div>
-----------------------------
-----------------------------
<div class="WADAResultThumbArea"><?php if($row_WADAfigure_lines['Thumbnail'] = '1') {?>show images<a href="figure_lines_Detail.php?Line_Id=<?php echo(rawurlencode($row_WADAfigure_lines['Line_Id'])); ?>" title="<?php echo $row_WADAfigure_lines["Line_Name"]; ?>"><img class="WADAResultThumb" border="0" src="images/TESTIMAGES/<?php echo $row_WADAfigure_lines['Filename']; ?>" /></a><?php } ?></div>
-----------------------------

Sign in to reply to this post

Jason ByrnesWebAssist

your recordset does not return a column named Thumbnail.

add the Thumbnail column to the select statement.

Sign in to reply to this post

Jared Lui

Here is my statement:

SELECT figure_lines.Line_Id, Line_Name, Line_Nickname, Start_Decade, End_Decade, Manufacturer, `Size`, Cat_1, Cat_2, Cat_3, figure_lines.Approved, Locked, figure_lines.Added_By, Line_Text, picture.Filename, picture.Thumbnail
FROM figure_lines
INNER JOIN picture ON figure_lines.Line_Id = picture.Line_Id
ORDER BY Line_Name DESC

Sign in to reply to this post

Jason ByrnesWebAssist

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.

Sign in to reply to this post

Jared Lui

Here is a .rar file of the php page: figure_lines_Results.rar

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)

Sign in to reply to this post

Jason ByrnesWebAssist

this line:
<?php if($row_WADAfigure_lines['Thumbnail'] = '1') {?>


should be:
<?php if($row_WADAfigure_lines['Thumbnail'] == '1') {?>

Sign in to reply to this post

Jared Lui

That worked, sorta.
I have the code in the wrong place.

The row is still being returned but the image is not. So I moved the <?php } ?> to before to </td> and it works fine. Thanks!

Only issue now is that the row count is still counting both rows. So it shows only 1 row visually, the counter says 1 of 2 of 2.

Sign in to reply to this post

Jason ByrnesWebAssist

try adding GROUP BY picture.Line_Id at the end of the query

Sign in to reply to this post
loading

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