MySQL查询与两个表的PHP [英] Mysql Query with two tables php
本文介绍了MySQL查询与两个表的PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何用php中的两个表进行查询?
I was wondering how to do a query with two tables in php?
我有这个查询
?php
$sQuery = "Select * From tb_columnas Where col_Status='activo' Order by col_ID DESC";
$result = mysql_query($sQuery, $cnxMySQL) or die(mysql_error());
$rows_result = mysql_fetch_assoc($result);
$total_rows_result = mysql_num_rows($result);
if ($total_rows_result > 0){
do {
$id_columnas = $rows_result ['col_ID'];
$col_Titulo = $rows_result ['col_Titulo'];
$col_Resumen = $rows_result ['col_Resumen'];
$col_Fecha = $rows_result ['col_Fecha'];
$col_Autor = $rows_result ['col_Autor'];
?>
但是我想将col_Autor与另一个表(tb_autores)中的au_Nombre进行比较,并从中获取au_Photo和其他值,我该怎么做?
But I'd like to compare the col_Autor with au_Nombre which is in another table (tb_autores) and get au_Photo and other values from it, how can I do that?
推荐答案
通过在FROM子句中指定两个表并在where子句中建立关系,可以在不使用JOIN关键字的情况下执行简单的联接查询.
You can do a simple join query without using the JOIN keyword by specifying the two tables in the FROM clause and establishing a relationship in the where clause.
例如
SELECT columns
FROM table1, table2
WHERE table1.field = table2.field
这篇关于MySQL查询与两个表的PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文