更新:由于第一个问题已解决(谢谢 - 我将第一个问题保留在底部供您查看),正确的连接现在可以正常使用。问题是它只拉入那些有联系的照片。无论它们是否有连接,我将如何提取所有照片?
添加 LEFT JOIN 而不是 JOIN 似乎会拉入所有照片,除了它向没有任何...的照片添加“连接”......有点奇怪。
这很难解释,但我会尽力而为。首先,让我为冗长的标题道歉,我只是试图让它尽可能详细。
这是关于在画廊中显示照片(user_album2 表)。每张照片都会显示“连接”(来自 user_connected 表)。user_connected 表的一个示例是:
fk_pic_id | fk_user_id | fk_user_id_conn
这些列中的每一列都是 INT,拉取照片 ID #,建立连接的用户 ID #,以及连接的用户 ID #。
您在以下代码中看到的所有“get_”函数都是提取用户信息的简单函数(因此,如果它是“get_profession”,它将获得职业 id #)。
$query = mysql_query("SELECT a.pic_id, a.fk_user_id as uid, a.picture_number, a.picture_name, a.id, a.featuredphoto, c.fk_pic_id, GROUP_CONCAT(CONVERT(c.fk_user_id_conn, CHAR(8))) as cuids
FROM user_album2 a LEFT JOIN user_connected c ON a.pic_id = c.fk_pic_id GROUP BY a.pic_id ORDER BY RAND() LIMIT 40") or die(mysql_error());
while ($row = mysql_fetch_array($query)) {
$pic_id = $row['pic_id'];
$userid = $row['uid'];
$photonum = $row['picture_number'];
$photo = $row['picture_name'];
$photoid = $row['id'];
$featured = $row['featuredphoto'];
$photogid = $row['fk_photog_id'];
$modelid = $row['fk_model_id'];
$cuids = explode(',',$row['cuids']);
if (get_profession($userid) == 1) {
$modeltag = get_name($userid);
$modelpic = get_photo($userid);
$modelLink = get_profile_link($userid);
foreach ($cuids as $c) {
$cprof = get_profession($c);
if ($cprof == 2) {
$photogtag = get_name($c);
$photogpic = get_photo($c);
$photogLink = get_profile_link($c);
}
}
} elseif (get_profession($userid) == 2) {
$photogtag = get_name($userid);
$photogpic = get_photo($userid);
$photogLink = get_profile_link($userid);
foreach ($cuids as $c) {
$cprof = get_profession($c);
if ($cprof == 1) {
$modeltag = get_name($c);
$modelpic = get_photo($c);
$modelLink = get_profile_link($c);
}
}
}
$classMargin = $modeltag && $photogtag ? ' add-bot-margin':'';
$myreturn .= '<li>'
.'<div class="inner">'
.'<img border="0" alt="" src="'. $baseurl . $photo .'&w=188&h=150&zc=1" />'
.'<div class="details">'
.'<a href="'. $baseurl .'photos/'. $userid .'/'. $photoid .'/'. $photonum .'" class="img-link">view image <strong>here</strong></a>'
.'<div class="info-contain-details">';
if ($modeltag) {
$myreturn .= '<div class="details-info model-info'. $classMargin .'">'
.'<a href="'. $baseurl . $modelLink .'" class="link-image"><img border="0" alt="" src="'. $baseurl .'img.php?src=/memberpictures/'. $modelpic .'&w=30&h=30&zc=1" /></a>'
.'<div class="photo-info">'
.'<a href="'. $baseurl . $modelLink .'" class="link-view-more">view more from</a>'
.'<a href="'. $baseurl . $modelLink .'" class="link-username">'. $modeltag .'</a>'
.'</div>'
.'</div>';
}
if ($photogtag) {
$myreturn .= '<div class="details-info photog-info">'
.'<a href="'. $baseurl . $photogLink .'" class="link-image"><img border="0" alt="" src="'. $baseurl .'img.php?src=/memberpictures/'. $photogpic .'&w=30&h=30&zc=1" /></a>'
.'<div class="photo-info">'
.'<a href="'. $baseurl . $photogLink .'" class="link-view-more">view more from</a>'
.'<a href="'. $baseurl . $photogLink .'" class="link-username">'. $photogtag .'</a>'
.'</div>'
.'</div>';
}
$myreturn .= '</div>'
.'<span class="details-bg"></span>'
.'</div>'
.'</div>'
.'</li>';
}
已修复:[出于某种原因,我这辈子都无法让专业部分正常显示。应该是:如果照片的职业所有者是模特,那么它应该检查照片与摄影师的联系(模特 = 1,摄影师 = 2)。我在“user_connected”表中有几行指向同一张照片,但是当它应该是一个模型和一个摄影师时,它一直显示相同的 2 个用户(两个“模型”),就是这样。] - 缺少一个“= " 登录 $cfprof if 语句,DOH!
如果您需要任何其他信息,请告诉我,并且一如既往地非常感谢任何帮助!