|
 |
|
อยากรู้ วิธีทำระบบสุ่มแบนเนอร์ (Random Banner With PHP) |
|
 |
|
|
 |
 |
|
Code (PHP Random Banner สุ่ม Banner จากฐานข้อมูล MySQL)
<?
mysql_connect("localhost","root","root");
mysql_select_db("thaicreate");
$strSQL = "SELECT * FROM banner WHERE 1 ORDER BY RAND() LIMIT 1 ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
echo "<img src='path/".$objResult["img-name"]."'>";
}
?>
|
 |
 |
 |
 |
Date :
2009-10-02 17:37:30 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
..,,^^
ขอบคุณมาก ๆ นะคะ
|
 |
 |
 |
 |
Date :
2009-10-03 00:05:57 |
By :
ไอติม |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ต้องเอาโค๊ดดูครับ เดี๋ยวมีคนมาตอบ
|
 |
 |
 |
 |
Date :
2009-10-03 01:03:44 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ให้ทายว่า ไม่เจอ ตาราง banner ไม่ก็ติดต่อฐานข้อมูลไม่ได้ อิอิ
|
 |
 |
 |
 |
Date :
2009-10-03 01:19:14 |
By :
danya |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
=,=' ช่วยดูหั้ยนู๋ หน่อยนะ คะ แก้หลายวันแล้ว ไม่รู้ ผิดตรงไหน
<?
include "connect.php";
$sql = "Select Min(no) minimum From tb_banner;";
$result = mysql_query($sql);
while ($dbarr = mysql_fetch_array($result))
{
$min = $dbarr['minimum'];
}
$sql = "Select Max(no) maximum From tb_banner;";
$result = mysql_query($sql);
while ($dbarr = mysql_fetch_array($result))
{
$max = $dbarr['maximum'];
}
$random_banner = rand($min,$max);
$sql = "Select * From tb_banner Where no = $random_banner;";
$result = mysql_query($sql);
while ($dbarr = mysql_fetch_array($result))
{
$photo_file = $dbarr['photo'];
}
echo "<img scr=$photo_file border=0>";
mysql_close($link);
?>
|
 |
 |
 |
 |
Date :
2009-10-03 01:42:25 |
By :
ไอติม |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<?
$sql="SELECT * FROM promotion ORDER BY RAND()LIMIT 1 ";
$result=$DB->query($sql);
$row=$DB->fetch_array($result);
?>
<img src="admin/promotion/promotion/<?=$row['img_pro']?>" width="975" height="546" alt="">
|
 |
 |
 |
 |
Date :
2009-10-03 06:46:33 |
By :
crowing |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|