|
Posted by David Haynes on 01/09/06 04:57
kiqyou_vf wrote:
> I have a page that displays search results. With each entry returned, I
> want to be able to display rows from 2 or more tables.
>
> table.qcbd has a keywords column that I want to search and
> table.qcbd_home has a description that I want to include in the search
> results. So if a search for "cups" returned 8 results, I would want
> each result to have information from table.qcbd AND table.qcbd_home.
> I'm not exactly sure how to go about doing this. I've tried some really
> messy coding, putting a query INSIDE of the while loop, lol- that
> didn't work.
>
> This is not the code, but I'll describe what I want to do like this:
> SELECT * FROM qcbd, qcbd_ghours WHERE keywords = $_GET['search']
>
> I would then do a loop and extract all of the returned rows from both
> tables. The problem I'm running into is that the returned rows dont
> line up.
>
> Hope this clears things up. As for the code, I don't really have
> anything of use to show you. Thanks!
>
Do table.qcbd and table.qcbd_home have a column of data that is a)
unique row in each table and b) defines some relationship between the
two tables? If so, you need to join the two tables based upon that
column. If not, the two tables are probably going to be joined with a
sub-select.
To join two tables you need to have an element in common to join them
on. The result may be one or more rows depending upon the nature of the
data in the joining columns.
It sounds like you want something like:
select qcdb_hours
from gcdb_home
where ??? in (
select ????
from qcdb
where keywords = '$_GET['search']'
)
At any rate, this seems to be more of a SQL problem rather than a PHP
problem. I would suggest you move your query over to one of the mysql
news groups.
-david-
Navigation:
[Reply to this message]
|