森林之原
五月 23, 2012, 11:23:22 pm *
歡迎光臨, 訪客. 請先 登入註冊一個帳號.

請輸入帳號, 密碼以及預計登入時間
新聞: CPG 1.4.3 繁體中文完成,請到 CPG 的版面下載。
 
   首頁   說明 搜尋 日曆 登入 註冊  
頁: [1]   向下
  寄送主題  |  列印  
作者 主題: 分享--在首頁加入隨機圖片  (閱讀 6143 次)
0 會員 以及 1 訪客 正在閱讀本篇主題.
itski
訪客
« 於: 一月 17, 2005, 02:25:47 am »

是我在網路上問人然後自己修改成功後   跟大家分享




首先要先裝eXtreme styles這個外掛這樣才可以在.tpl執行php 




第二步驟:
因為我的論壇是用phpbb         首頁是裝EZportal外掛
所以以下這段code我裝在  portal_body.tpl 裡面
有一些你得再修改,像是資料庫的名字、密碼、路徑,還有看你要怎麼資料就再加進去!


程式碼:
<table width="100%" cellpadding="2" cellspacing="1" border="0" class="forumline">
<tr>
<td class="catHead" height="25"><span class="genmed"><b>隨機圖片</b></span></td>
</tr>
<tr>
<td class="row1" align="center">
<?php 
//<?php 

//***Enter Path information here*** 
//***absolute path to main coppermine directory*** 

$copperminepath './your_path'//***YOU MUST CHANGE THIS*** 

//This connects to the mysql DB 
//***change username and password below*** 

$MZrandompic = @mysql_connect('localhost''username''password'); //***YOU MUST CHANGE THIS*** 

if (!$MZrandompic) { 
echo( 
'<p>Unable to connect to the ' 
'database server at this time.</p>' ); 
exit(); 


//select photo DB 
//***YOU MUST CHANGE THIS*** 

if (! @mysql_select_db('your data base name') ) { 
die( 
'<p>Unable to locate the picture ' 
'database at this time.</p>' ); 


//This gets a random picture record from the database and 
//the picture's location and displays it 

$MZresult = @mysql_query("SELECT * FROM cpg132_pictures ORDER BY RAND() LIMIT 0,1"); 
if (!
$MZresult) { 
die(
'<p>Error performing query: ' mysql_error() . 
'</p>'); 


while ( 
$MZrow mysql_fetch_array($MZresult) ) { 

$albumid $MZrow['aid']; //This gets the picture's associated album name 
$pos $MZrow['pid']; //This finds the picture's coppermine location 
$filepath $MZrow['filepath']; 
$filename $MZrow['filename']; 

echo(
'<P ALIGN=center>'); 

echo(
'<a target = "_new" href="' $copperminepath '/displayimage.php?album=' $albumid 
'&pos=-' $pos '">'); //make thumbnail clickable 

echo('<IMG SRC="' $copperminepath '/albums/'); //append base dir structure 
echo( $filepath .normal_$filename 
'" alt=' $MZrow['title'] . ' ''border=0 height=150>' '</a> </br>'); //outputs path from /userspics 
//echo('<FONT SIZE=2>'); 
echo($MZrow['title']); 


//This displays the picture's album name and 
//links it to the coppermine album 

$MZalbumresult = @mysql_query("SELECT * FROM cpg132_albums WHERE aid = '$albumid'"); 
if (!
$MZalbumresult) { 
die(
'<p>Error performing query: ' mysql_error() . 
'</p>'); 


while ( 
$MZalbumname mysql_fetch_array($MZalbumresult) ) { 
echo(
'<FONT SIZE=1>'); 
echo(
'<P ALIGN=center>'); 

echo(
'<a href="' $copperminepath 
'/thumbnails.php?album=' $albumid '">' 
$MZalbumname['title'] . '</a>' '</p>'); 


if (! @
mysql_select_db('your data base name') ) { 
die( 
'<p>Unable to reload the main website ' 
'database at this time.</p>' ); 


//?>

</td>
</tr>
</table>
</br>
   


這樣應該就OK了

向版主檢舉   已記錄
lulala
訪客
« 回覆文章 #1 於: 七月 04, 2005, 11:34:33 am »

那要如何加到vbb的首頁去壓
向版主檢舉   已記錄
samer
訪客
« 回覆文章 #2 於: 九月 01, 2005, 04:12:33 am »

感謝itski 兄提供的方法
但是我現在又有一個問題耶~
我的這一支PHP改完後,也可以執行了,但是
在這一行
$MZrandompic = @mysql_connect('localhost', 'username', 'password'); //***YOU MUST CHANGE THIS***


有username和passeord耶~
那不是只要有人把這支PHP下載回去,就看到mysql的帳號和密碼了嗎?
向版主檢舉   已記錄
Andrew::
魔,羯
*
離線 離線

文章: 217



個人網站
« 回覆文章 #3 於: 九月 01, 2005, 10:53:34 am »

php的檔案是下載不了的....
向版主檢舉   已記錄

samer
訪客
« 回覆文章 #4 於: 九月 01, 2005, 09:26:01 pm »

php的檔案是下載不了的....

A~~~真的是這樣耶!
感謝感謝
!!
這樣我就放心了~
向版主檢舉   已記錄
頁: [1]   向上
  寄送主題  |  列印  
 
前往:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006, Simple Machines LLC Valid XHTML 1.0! Valid CSS!