$sql=mysql_query("SELECT a.ssmid, a.image,b.ssmid,b.image,c.ssmid,c.image FROM a user_photos_offline INNER JOIN user_profile_pic b on a.ssmid = b.ssmid INNER JOIN user_family_photos c on a.ssmid = c.ssmid");

  while($row=mysql_fetch_assoc($sql)){
      echo $row['image'];
  }


我想从数据库中选择所有图像,我有3个表,这些是所有表的表名user_photos_offlineuser_profile_picuser_family_photos,列名是image

在3个表中,我有同一列ssmid,现在我要为这3个表选择图像

最佳答案

要单独参考图像,请使用AS

SELECT
  a.ssmid, a.image AS a_image,
  b.ssmid, b.image AS b_image,
  c.ssmid, c.image AS c_image
 FROM user_photos_offline a
 INNER JOIN user_profile_pic b on a.ssmid = b.ssmid
 INNER JOIN user_family_photos c on a.ssmid = c.ssmid


在PHP中,您的索引将更改为以下标识符:

while($row=mysql_fetch_assoc($sql)){
     echo $row['a_image'];
     echo $row['b_image'];
     echo $row['c_image'];
}

10-05 19:07