เข้ามาอ่านแล้วก็เงียบหายไป เพราะว่าต้องกลับไปทดลอง บางครั้งมีทบทวนเรื่องภาษา PHP
ลองผิดลองถูกเพื่อจะได้เกิดประสบการณ์ครับ ลองทำตามคำแนะนำกระทู้ด้านบน แต่ไม่มั่นใจ
ทำได้ถูกต้องไหม เพราะว่ามีเออเรอร์ขึ้นครับ
สร้างไฟล์ใหม่ชื่อว่า new-ad.php ใส่โค๊ดตามนี้
<?
include ('SSI.php');
function findIMG($text){
preg_match_all('/[img].*?[/img]/i',$text,$page);
foreach($page as $value)
$src = substr($value[0],5);
$src = substr($src,0,-6);
return($src);
}
function ssi_pic($num_top = 12,$order,$board = array()){
global $db_prefix, $scripturl, $smcFunc;
$request = $smcFunc['db_query']('', '
SELECT t.id_topic,m.body,m.subject
FROM {db_prefix}messages m,{db_prefix}topics t
WHERE t.id_first_msg=m.id_msg AND t.id_board IN('. implode(',',$board) .')
ORDER BY t.'.$order.' DESC
LIMIT '.$num_top,
array(
)
);
$posts = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
// Build the array.
$topics[] = array(
'id' => $row['id_topic'],
'body' => $row['body'],
'subject' => $row['subject']
);
}
$smcFunc['db_free_result']($request);
foreach ($topics as $data){
$topic = "index.php?topic=".$data['id'];
$srcPic = findIMG($data['body']);
$subject = $data['subject'];
echo '<div class="boxpGal">
<div class="picpGal"><a href="'.$srcPic.'" title="คลิ๊กเพื่อดูภาพเต็ม."><img src="'.$srcPic.'" width="150" alt="" />[/url]</div><center>'.mb_substr($subject,0,20,'UTF-8').'</center>
<div class="viewAllpic"><a href="'.$topic.'" target="_blank"><font color="#0000FF">อ่านเพิ่มเติม...</font>[/url]</div>
</div>';
}
}
echo'<div class="cat_bar">
<h3 class="catbg">คู่มือการซ่อม และวายริ่งรถยนต์ ล่าสุด...</h3></div>';
echo''.ssi_pic(6,'ID_TOPIC', array(25,436,656,739)).'';
?>
ส่วนที่เรียกใช้งานแทรกโค๊ด iFrame ประมาณนี้
<iframe src="https://car.auto-nkp.com/new-ad.php"></iframe>
นำไปแทรกในไฟล์ Boardindex.template.php ขึ้นเออเรอร์
syntax error, unexpected '<'
ทีนี้ไปไม่เป็นเลย วานผู้รู้ชี้แนะครับ ขอบคุณล่วงหน้าครับ
โค้ด
<?php
include 'SSI.php';
function findIMG( $text )
{
preg_match_all( '/[img].*?[/img]/i', $text, $page );
foreach ( $page as $value ) {
$src = substr( $value[0], 5 );
}
$src = substr( $src, 0, -6 );
return ( $src );
}
function ssi_pic( $num_top = 12, $order, $board = array() )
{
global $db_prefix, $scripturl, $smcFunc;
$request = $smcFunc['db_query']( '', '
SELECT t.id_topic,m.body,m.subject
FROM {db_prefix}messages m,{db_prefix}topics t
WHERE t.id_first_msg=m.id_msg AND t.id_board IN(' . implode( ',', $board ) . ')
ORDER BY t.' . $order . ' DESC
LIMIT ' . $num_top, array()
);
$posts = array();
while ( $row = $smcFunc['db_fetch_assoc']( $request ) ) {
// Build the array.
$topics[] = array(
'id' => $row['id_topic'],
'body' => $row['body'],
'subject' => $row['subject']
);
}
$smcFunc['db_free_result']( $request );
foreach ( $topics as $data ) {
$topic = $scripturl . "?topic=" . $data['id'];
$srcPic = findIMG( $data['body'] );
$subject = $data['subject'];
echo '
<div class="boxpGal">
<div class="picpGal">
<a href="' . $srcPic . '" target="_blank" title="คลิ๊กเพื่อดูภาพเต็ม.">
<img src="' . $srcPic . '" width="150">
</a>
</div>
<div style="text-align: center;">' . mb_substr( $subject, 0, 20, 'UTF-8' ) . '</div>
<div class="viewAllpic">
<a href="' . $topic . '" target="_blank">
<font color="#0000FF">อ่านเพิ่มเติม...</font>
</a>
</div>
</div>';
}
}
echo '
<div class="cat_bar">
<h3 class="catbg">คู่มือการซ่อม และวายริ่งรถยนต์ ล่าสุด...</h3>
</div>';
ssi_pic( 6, 'ID_TOPIC', array( 25, 436, 656, 739 ) );
ส่วนถ้าจะเอาไปใส่ในไฟล์ boardIndex.template.php
ก็ใส่ประมาณนี้
echo '<iframe src="
https://car.auto-nkp.com/new-ad.php "></iframe>';
เออเร่อแจ้งมาว่า syntax error, unexpected น่าจะมีการปิดแท็กหรือพลาดตรงใส่ ฟันหนูไม่ครบครับ
เช่น echo '> แบบนี้ หรือ ฯลฯ