我真的希望您可以为我澄清关于使用 php 进行 JOIN 的问题,因为我真的很难接受它的工作原理。
基本上我有两张桌子,一张给高级会员,一张给这些会员的粉丝。所以我想从成员($memberid
)是粉丝的“高级”表中获取某些信息。
Premium = id, name, avatar, town, etc, etc
Fans = fan($memberid), fanee(Premium ID)
所以我现在有这个代码:
<?php
$get_connections_sql = "SELECT id, name, avatar, town FROM premium LEFT JOIN fans ON fans.fanee=premium.id WHERE fans.fan=$memberid LIMIT 18";
$get_connections_res = mysqli_query($con, $get_connections_sql);
if(mysqli_affected_rows($con)>0){
while ($connections = mysqli_fetch_assoc($get_connections_res)){
$connectionid = $connections['id'];
$connectionname = $connections['name'];
$connectiontown = $connections['town'];
$connectionavatar = $connections['avatar'];
$connections .= "
<div class=\"connectionHolder\"><img class=\"connection\" src=\"uploads/avatars/pro/$connectionavatar\" /></div>
";
}
}else{
$connections = "
<div class=\"noContent\">There are no connections to be shown</div>
";
}
?>
这是返回 else 条件,所以我的 JOIN 行一定有问题 - 谁能指出我正确的方向。