 |
การนำตัวแปรใน array มาใช้ในการสร้างเงื่อนไขต้องทำอย่างไร..ถ้าผู้โพสต์อัปโหลดรูปตัวเองให้แสดง path อีกอย่าง และถ้าเลือกรูปที่มีให้ ให้แสดง path ของรูปอีกอย่าง |
|
 |
|
|
 |
 |
|
โค้ดในการดึงข้อมูลมาแสดง และได้สร้างเงื่อนไขในการนำรูปออกมาโชว์ คือ ถ้าผู้โพสต์อัปโหลดรูปตัวเองให้แสดง path อีกอย่าง และถ้าเลือกรูปที่มีให้ ให้แสดง path ของรูปอีกอย่าง
โค้ดที่โพสต์โชว์รูปได้ทั้งสอง(อัปโหลดและเลือกรูป) แต่กลับแสดงออกมาแค่หัวข้อเดียว ขอคำชี้แนะด้วยครับ
Code
function ssi_recentComment($num_recent = 10, $output_method = 'echo')
{
global $context, $db_prefix,$settings, $modSettings, $scripturl, $txt, $ID_MEMBER;
global $func;
// Display all user comments
$request = db_query("
SELECT
c.ID_FILE, c.ID_COMMENT, c.date, c.comment, c.ID_MEMBER,
c.lastmodified,c.modified_ID_MEMBER, m.posts, m.realName,m.avatar, c.approved, IFNULL(m.realName, m.memberName) AS posterName,f.ID_FILE,f.title, f.totaldownloads,f.commenttotal,a.ID_ATTACH,a.ID_MEMBER AS Members
FROM {$db_prefix}down_comment as c
LEFT JOIN {$db_prefix}members AS m ON (c.ID_MEMBER = m.ID_MEMBER)
LEFT JOIN {$db_prefix}down_file AS f ON (f.ID_FILE = c.ID_FILE)
LEFT JOIN {$db_prefix}attachments AS a ON (c.ID_MEMBER = a.ID_MEMBER)
ORDER BY c.ID_COMMENT DESC LIMIT 0,$num_recent");
$contexts= array();
while ($row = mysql_fetch_assoc($request))
{
// If we want to limit the length of the post.
if (!empty($length) && $func['strlen']($row['comment']) > $length)
{
$row['comment'] = $func['substr']($row['comment'], 0, $length);
// The first space or line break. (<br />, etc.)
$cutoff = max(strrpos($row['comment'], ' '), strrpos($row['comment'], '<'));
if ($cutoff !== false)
$row['comment'] = $func['substr']($row['comment'], 0, $cutoff);
$row['comment'] .= '...';
}
$row['comment'] = parse_bbc($row['comment']);
$contexts[] = array(
'ID_FILE' => $row['ID_FILE'],
'ID_COMMENT' => $row['ID_COMMENT'],
'title' => $row['title'],
'totaldownloads' => $row['totaldownloads'],
'commenttotal' => $row['commenttotal'],
'comment' => $row['comment'],
'ID_MEMBER' => $row['ID_MEMBER'],
'posts' => $row['posts'],
'attach' => $row['ID_ATTACH'],
'avatar' => $row['avatar'],
'urlavatar' => '<img src="'.$scripturl.'/index.php?action=dlattach;attach='.$row['ID_ATTACH'].';type=avatar" border="0" width="45px" height="45px">',
'fileavatar' => '<img src="avatars/'.$row['avatar'].'" border="0" width="45px" height="45px">',
'realName' => $row['posterName'],
);
}
mysql_free_result($request);
// Just return it.
if ($output_method != 'echo' || empty($contexts))
return $contexts;
echo '
<table cellspacing="0" cellpadding="2" border="0" align="center" width="100%">';
foreach ($contexts as $context)
//โค้ดเงื่อนไขในการโชว์รูป
if($context['avatar']==""){
$context['avatar']=$context['urlavatar'];
}else {
$context['avatar']=$context['fileavatar'];
}
echo '
<tr>
<td valign="top" class="smalltext">
', $context['ID_COMMENT'],'</td><td class="smalltext">',$context['fileavatar'], '</td><td> ', $context['comment'], ' ', $txt[525],' <a href="' . $scripturl . '?action=profile;u=' .$context['ID_MEMBER'] . '">' . $context['realName'] . '</a> ',$txt['smf88'], ' <a href="' . $scripturl . '?action=downloads;sa=view;id=' .$context['ID_FILE'] . '">' . $context['title'] . '</a> ['.$txt['downloads_cat_downloads'].':' . $context['totaldownloads'] . '|'.$txt['downloads_text_comments'].':' . $context['commenttotal'] .']<br/> ', $txt[30], ' ' . timeformat($context['date']) . '
</td>
</tr>
';
echo '
</table>';
}
Tag : PHP
|
|
 |
 |
 |
 |
Date :
2011-03-09 21:39:31 |
By :
mc |
View :
1090 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ if เอาง่าย ๆ ครับ เช่น
Code (PHP)
if($context['avatar'] != "")
{
$img = $context['avatar'];
}
else
{
$img = "default.gif";
}
|
 |
 |
 |
 |
Date :
2011-03-11 11:50:07 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|