Hi,
i have a database in which i have 3 tables
1 contact
2 website
3 emails
im trying to bring up information from all 3 that related. The thing is
table 3 mite have an array of related information i.e if i looked for related info on 'books' i get 1 reuslt from table 1, 2 results table 2 and 5 results from table 3
the thing is i used one query to search all three
"SELECT * from contact,website, email WHERE...."
my problem lies when trying to loop through the results in which the result of a table is more than one as i get repetition of the same information.
Now to overcome this i had to do 2 separate queries. in order to properly sort through the results but is there a way to do it without having to do 2 separate searches on the same issue??
Kendall
Looping through results from a Database Query
Moderator: General Moderators
sounds like it's time for a JOIN-tutorial 
http://www.google.de/search?&q=sql%20join%20tutorial
http://www.baycongroup.com/sql_join.htm
http://www.w3schools.com/sql/default.asp
http://www.google.de/search?&q=sql%20join%20tutorial
http://www.baycongroup.com/sql_join.htm
http://www.w3schools.com/sql/default.asp
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
Looping through results from a Database Query
Hi,
Uh...Actually the problem is not there its is where i have to display the results
see its lke this :
i have a table 1 with sone ones name jane doe
in table 3 she has 3 webistes
in a statement i do "SELECT * FROM table1,table3 WHERE table1.id = 'jane' AND table3.id = table1.id"
from this i get
TABLE1 TABLE3
jane doe jane@email.com
jane doe doe@email.com
jane doe mail@email.com
SEE... here's my thing
in order to do a loop i must loop through the TABLE 3 in order to get the emails printed rite?
so i do a loop but for every email i get a repetition of jane doe!!!
obviously theres one jane doe record in table 1 but why did it repeat 3 times in the mysql print?
so now im trying to see if i can sift tru the results to get the info with out repeating the dame thing over again
Kendall
Uh...Actually the problem is not there its is where i have to display the results
see its lke this :
i have a table 1 with sone ones name jane doe
in table 3 she has 3 webistes
in a statement i do "SELECT * FROM table1,table3 WHERE table1.id = 'jane' AND table3.id = table1.id"
from this i get
TABLE1 TABLE3
jane doe jane@email.com
jane doe doe@email.com
jane doe mail@email.com
SEE... here's my thing
in order to do a loop i must loop through the TABLE 3 in order to get the emails printed rite?
so i do a loop but for every email i get a repetition of jane doe!!!
obviously theres one jane doe record in table 1 but why did it repeat 3 times in the mysql print?
so now im trying to see if i can sift tru the results to get the info with out repeating the dame thing over again
Kendall
I don't see what the problem is with any certianty. Isn't this as easy as just a
If you managed to gather all the information using one query, then what else is there to do?
Cheers,
BDKR
Code: Select all
while($row=(fetch_assoc/array/object))
{ /* display contents of $row */ }Cheers,
BDKR
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
Looping through results from a Database Query
No it isnt in the case of
TABLE1
jane doe
jane doe
jane doe
TABLE 2
website
another website
TABLE3
email 1 for website
email 2 for another website
email 3 for another website
then i
print the name jane doe
i did a do {
print the website
}while($row=(fetch_assoc/array/object))
and do {
print the email
}while($row=(fetch_assoc/array/object))
problem is
i get
jane doe
website
website
website
email1
email2
email3
Kendall
TABLE1
jane doe
jane doe
jane doe
TABLE 2
website
another website
TABLE3
email 1 for website
email 2 for another website
email 3 for another website
then i
print the name jane doe
i did a do {
print the website
}while($row=(fetch_assoc/array/object))
and do {
print the email
}while($row=(fetch_assoc/array/object))
problem is
i get
jane doe
website
website
website
email1
email2
email3
Kendall