Hi,
I got two questions thats been bugging me but I start with the first one as its quite much to explain.
I'm trying to create a LEFT JOIN on two tables and then output everything, I have no problems getting the information but once I want to output it I get a problem.
Lets say I select a topic and then do a LEFT JOIN on comments I now output it in php like this:
[PHP]$topics = new topicBinding();
foreach($topics->getTopics() as $topic) {
...
}[/PHP]
The sql SELECT will look something like this:
[PHP]$sql = "SELECT topics.name, comments.commen t FROM topics " .
"LEFT JOIN comments ON topics.id = comments.topic_ id " .
"WHERE topics.id = '1'";[/PHP]
And here is the problem: because each topic have more comments I will get a new $topic for each comment instead of each topic.. so the topic would output as many times as the the num_rows of the comment,
output example:
[HTML]ID NAME COMMENT
1 first topic comment 1
1 first topic comment 2[/HTML]
I will of course not want to output the topic over and over again and instead I want to control it like this:
[PHP]$topics = new topicBinding();
foreach($topics->getTopics() as $topic) {
...
foreach($topic['comment'] as $comment) {
}
}[/PHP]
Is this possible?
I got two questions thats been bugging me but I start with the first one as its quite much to explain.
I'm trying to create a LEFT JOIN on two tables and then output everything, I have no problems getting the information but once I want to output it I get a problem.
Lets say I select a topic and then do a LEFT JOIN on comments I now output it in php like this:
[PHP]$topics = new topicBinding();
foreach($topics->getTopics() as $topic) {
...
}[/PHP]
The sql SELECT will look something like this:
[PHP]$sql = "SELECT topics.name, comments.commen t FROM topics " .
"LEFT JOIN comments ON topics.id = comments.topic_ id " .
"WHERE topics.id = '1'";[/PHP]
And here is the problem: because each topic have more comments I will get a new $topic for each comment instead of each topic.. so the topic would output as many times as the the num_rows of the comment,
output example:
[HTML]ID NAME COMMENT
1 first topic comment 1
1 first topic comment 2[/HTML]
I will of course not want to output the topic over and over again and instead I want to control it like this:
[PHP]$topics = new topicBinding();
foreach($topics->getTopics() as $topic) {
...
foreach($topic['comment'] as $comment) {
}
}[/PHP]
Is this possible?
Comment