如何从多个MySQL表中获取数据

时间:2010-06-10 05:27:51

标签: php mysql

我正在寻找php + MySQL + jquery的一些帮助 我有2张桌子

表1 表1有4个colume (id,title,desc,thumb_img)

tabel2 表2有3个colume(id,table1id,img)

我只想将2表与$ _get ['QS']的值进行比较; 并显示两者的记录(title,desc,img)

期待帮助。:)

2 个答案:

答案 0 :(得分:2)

SELECT t1.title, t1.desc, t2.img
FROM table1 AS t1
JOIN table2 AS t2
  ON t1.id=t2.table1id
WHERE somefieldyoudidntspecify=:qs

答案 1 :(得分:0)

<?php  
   $query="select * from table1 t1 inner join table2 t2 on t2.table1id = t1.id where SomeField = '". mysql_real_escape_string($_get['QS'])."'"
?>