问题:表一
A B C D // 属性
表二
C E F G //属性 C属性两个表中一样
给定了C
结果要把表一里的数据全部显示出来
表二有可能为空
解答:
$sql = "select a.A, a.B, a.C, a.D, b.E, b.F, b.G from Table1 a left join Table2 b on a.C = b.C";
$Conn = mysql_connect("localhost", "root","");
mysql_select_db("Table1",$Conn);
$RS = mysql_query($sql,$Conn);
//把结果集$RS第一行读入数组$rs
$rs = mysql_fetch_array($RS,MYSQL_ASSOC);
mysql_free_result($RS);
mysql_close($Conn);
print "
";
print_r($rs);
print "";
echo $rs["A"];
echo $rs["G"];
?>
阅读(3979) | 评论(0) | 转发(0) |