php - get info from 2 tables at once? -
i need info 2 tables in 1 query, searched on google , came joins? got code
mysql_query("select code, url apilinks, links apilinks.code='$code' , links.code='$code'");
but doesn't seem work, outpus mysql error
warning: mysql_num_rows(): supplied argument not valid mysql result resource in /home/codyl/public_html/projects/tests/tirl/code.php on line 18
i need have find url , code, in both links table , apilinks table, because url has variable, , 'apilinks' setup differently 'links' have same looking url has check both tables
i don't think error sql query, anyway:
your sql query generates cartesian product. every row in apilinks joined every row in links. want. need add join
condition clause.
from query, guess code
column want join on.
select links.code, url apilinks, links apilinks.code=links.code , links.code='$code'
or using explicit join, may more obvious you:
select links.code, url apilinks inner join links on apilinks.code=links.code links.code='$code'
Comments
Post a Comment