Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query returning 2 instances of 1st row

Status
Not open for further replies.

3Y3

Programmer
Sep 18, 2001
45
CA
I have set up a query (search form) that returns product data to the user. In one case, my product table is linked to a productStyles table (product table field contains an integer which is checked against the IDs in productStyles for something like 1 = "Blue Style").

However when I display the data on my page after a successful query the following happens:

If any of the product styles is 1 then it returns the data from productStyles twice (so in this case the product will display on screen "Style: Blue Style Blue Style"). All other products and thier styles however work.

The query:
select * from Homes inner join HomeStyles ON Homes.HomeStyle = HomeStyles.ID where ...(whatever conditions are set on the search form)

Then I just dump the style data to the page with
while($row=mssql_fetch_array($nt)){
echo "$row[Style]";
}



The Tables (HomeStyle in Homes should reference Style in HomeStyles. If Homes.HomeStyle = 1 then I get this problem)


HomeStyles
ID, Style, StyleType

Homes
ID, PlanNum, Name, SqFt, Levels, Bedrooms, HomeStyle



This is what happens when I don't actually use PHP/SQL for months while at school, ugh my brains! Thanks for any help with this matter.
 
Um....if there isnt a dup row in the table....probably post your code. put it in
Code:
 tags....nice to read :-)

Robert Carpenter 
Remember....eternity is much longer than this ~80 years we will spend roaming this earth.
ô¿ô
[URL unfurl="true"]http://www.robertcarpenter.net[/URL]
 
please post your table structure as well. there may be an anomaly in your join that creates the double row. although i note that you say other queries are working ok.
 
Oi!

I just spent 20 minutes putting together a full reply with tons of code and full database dumps for you guys to help me out, then I saw the issue.

Whenever I queried my HomeStyles Table from the web site, I would see the doubled data from ID = 1, however when i looked at the database table itself from within SQL server enterprise Manager (and queried it using the same code) it would show the proper table as seen here:

Code:
ID          Style                                             Style
1           Contemporary                                      H
2           Cottage                                           H    
3           Early American                                    A    
4           European                                          A    
5           Greek Revival                                     H    
6           Southern Colonial                                 H    
7           Victorian                                         H    
8           Tuck-Under                                        G    
9           Art Deco                                          H

HOWEVER, when i went to dump the data out to a text file (so i could copy and paste my table data for you guys to see), THIS is what I came to see in the txt file:

Code:
ID          Style                                             Style
1           Contemporary
Contemporary                        H    
2           Cottage                                           H    
3           Early American                                    A    
4           European                                          A    
5           Greek Revival                                     H    
6           Southern Colonial                                 H    
7           Victorian                                         H    
8           Tuck-Under                                        G    
9           Art Deco                                          H


Sigh. I have no clue HOW that got there (i typed in the single contemporary and all other data over twice when working with this issue). Regardless, I killed that row and put in new data and this time it working.

Thanks for the help!
 
Ignore the fact the table has 2 style fields :p the 2nd one got cut off for some reason (its StyleType).

Anyways, this is solved. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top