更新:由于第一个问题已经解决(谢谢 - 我保留了最底层的第一个问题供你查看),正确的连接现在已经很好了。问题是它只是拉入那些有连接的照片。如果他们有联系,我怎么拉所有照片呢?
添加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!
如果您需要任何其他信息,请告诉我,一如既往,我们非常感谢您的帮助!
答案 0 :(得分:0)
固定。问题出在foreach循环中,我需要有一个ELSE语句,将photogtag / modeltag设置为FALSE。
if ($cprof == 2 && $c != '') {
$photogtag = get_name($c);
$photogpic = get_photo($c);
$photogLink = get_profile_link($c);
} else {
$photogtag = false;
}