Page 1 of 1

Looping through results from a Database Query

Posted: Thu Jan 16, 2003 8:01 am
by kendall
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

Posted: Thu Jan 16, 2003 8:41 am
by volka

Looping through results from a Database Query

Posted: Thu Jan 16, 2003 9:13 am
by kendall
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

Posted: Thu Jan 16, 2003 10:21 am
by BDKR
I don't see what the problem is with any certianty. Isn't this as easy as just a

Code: Select all

while($row=(fetch_assoc/array/object))
    { /* display contents of $row */ }
If you managed to gather all the information using one query, then what else is there to do?

Cheers,
BDKR

Looping through results from a Database Query

Posted: Thu Jan 16, 2003 10:33 am
by kendall
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