TShopping
標題:
javascript php mysql輪播式廣告怎麼傳id值阿
[打印本頁]
作者:
woff
時間:
2010-6-12 22:43
標題:
javascript php mysql輪播式廣告怎麼傳id值阿
大大您好,小弟有各移惑
小弟寫了各輪播式廣告
功能都正常,但是小弟想點擊廣告時,會傳會該廣告id給javascript再傳給PHP寫入MYSQL
小弟目前,已經可以傳id了,但是永遠都是抓最後一個id值,請懂的大大指導一下,我把程式貼下面
<body onLoad="load()">
</body>
<div align="center">{literal}<script type="text/javascript" src="adv.php"></script>{/literal}</div>
複製代碼
adv.php
<?php
include "global.php";
echo 'document.write(\'<link rel="stylesheet" href="adv.css" type="text/css" />\');';
echo 'var xmlHttp;';
echo 'var xmlHttp2;';
echo 'var xmlHttp3;';
echo 'var imgWidth=700;';
echo 'var imgHeight=200;';
echo 'var _timeOut_=5000;';
echo 'var timeOut=_timeOut_;';
echo 'var timeOut2=_timeOut_/2;';
echo 'var adNum=0; var target="_blank"; var button_Texton=\'#000000\'; var button_Textoff=\'#ffffff\';';
echo 'var buttonLineOn="#99CC33"; var buttonLineOff="#333333";';
echo 'var imgId=new Array();';
echo 'var imgUrl=new Array();';
echo 'var imgText=new Array();';
echo 'var imgLink=new Array();';
echo 'var imgTitle=new Array();';
echo 'var imgAlt=new Array();';
echo 'var ver=2; var firstTime=true;';
echo 'document.write(\'<div id="ad_pic" class="block02">\');';
echo 'document.write(\'<div id="f_div">\');';
echo 'document.write(\'<div id="f_imgDiv">\');';
$sql = @mysql_query("SELECT * FROM net_headeradv ORDER BY num LIMIT 8");
$nowtime = mktime();
while ($row = mysql_fetch_array($sql)) {
$id = $row['id'];
$num = $row['num'];
$img = $row['img'];
$url = $row['url'];
$title = $row['title'];
$starttime = $row['starttime'];
$endtime = $row['endtime'];
if ($nowtime >= $starttime && $endtime >= $nowtime) {
echo 'imgId['.$num.'] = \''.$id.'\';';
echo 'imgUrl['.$num.'] = \''.$img.'\';';
echo 'imgText['.$num.'] = \''.$num.'\';';
echo 'imgLink['.$num.'] = \''.$url.'\';';
echo 'imgTitle['.$num.'] = \''.$title.'\';';
}
}
echo 'function b_change(n){';
echo 'adNum=n; window.clearInterval(theTimer); adNum=adNum-1; change();';
echo '}';
//計算載入幾張圖
echo 'var count=0;';
echo 'for (var i=0;i<imgUrl.length;i++) {';
echo 'if( (imgUrl[i]!="") && (imgText[i]!="")&& (imgLink[i]!="")) {';
echo 'count++;';
echo '} else {';
echo 'break;';
echo '}';
echo '}';
//gcsse
echo 'var each_width=Math.ceil((imgWidth-(count-1))/count);';
echo 'var last_width=imgWidth-each_width*(count-1)-(count)+1;';
echo 'function change(){';
echo 'if(adNum<(imgUrl.length-1))adNum++;';
echo 'else adNum=1;';
echo 'theTimer=setTimeout("change()", timeOut);';
echo 'document.getElementById("f_img").Id=imgId[adNum];';
echo 'document.getElementById("f_img").src=imgUrl[adNum];';
echo 'document.getElementById("f_img").title=imgTitle[adNum];';
//var f_img=document.getElementById("f_img");
//f_img.src=imgUrl[adNum];
echo 'document.getElementById("f_imgLink").href=imgLink[adNum];';
echo 'for (var i=1;i< count;i++){';
echo 'if (i !=adNum){';
echo 'document.getElementById(\'b\'+i).className="button";';
echo '}';
echo 'document.getElementById(\'b\'+adNum).className="on"; }';
echo '}';
echo 'document.write(\'<a id="f_imgLink" href="../\'+imgLink[adNum]+\'" target=_blank><img id="f_img" src="" width=\'+imgWidth+\' height=\'+imgHeight+\' border="0" title="" onClick="add()";></a>\');';
echo 'document.write(\'</div>\');';
echo 'document.write(\'<div id="f_infoDiv">\');';
echo 'document.write(\'<div id="f_buttonDiv">\');';
echo 'for (var i=count-1;i>=1;i--){';
echo 'document.write(\'<div id="div_bg\'+i+\'" class="bg"><a id="b\'+i+\'" href="javascript:b_change(\'+i+\')" class="button">\'+imgText[i]+\'</a></div>\');';
echo '}';
echo 'document.write(\'</div>\');';
echo 'document.write(\'</div>\');';
echo 'document.write(\'</div>\');';
echo 'document.write(\'</div>\'); change();';
echo 'function getHttpRequestObject(handler){';
echo 'var httpRequest=null;';
echo 'if(window.XMLHttpRequest){';
echo 'httpRequest=new XMLHttpRequest();';
echo '}else if(window.ActiveXObject){';
echo 'var msxmls=["Microsoft.XMLHttp","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp"];';
echo 'for(var i=0;i<msxmls.length;i++){';
echo 'try{';
echo 'httpRequest=new ActiveXObject(msxmls[i]);';
echo 'break;';
echo '}catch (e){';
echo 'return null;';
echo '}';
echo '}';
echo '}';
echo 'httpRequest.onreadystatechange=handler;';
echo 'return httpRequest;';
echo '}';
echo 'function makeRequest(httpRequest,url){';
echo 'httpRequest.open("GET",url,true);';
echo 'httpRequest.send(null);';
echo '}';
echo 'function loaddata(){';
echo 'if(xmlHttp.readyState==4){';
echo 'var xmlResult=xmlHttp.responseXML;';
echo 'var node=xmlResult.documentElement;';
echo 'if(node.getElementsByTagName("item")[0].firstChild.data!=0){';
echo 'document.getElementById("f_img").innerHTML="hit按鍵總共被按"+node.getElementsByTagName("item")[0].firstChild.data+"次!";';
echo '}';
echo '}';
echo '}';
echo 'function loaddata2(){';
echo 'if(xmlHttp2.readyState==4){';
echo 'var xmlResult2=xmlHttp2.responseXML;';
echo 'var node2=xmlResult2.documentElement;';
echo 'if(node2.getElementsByTagName("item")[0].firstChild.data!=0){';
echo 'document.getElementById("f_img").innerHTML="hit按鍵總共被按"+node2.getElementsByTagName("item")[0].firstChild.data+"次!";';
echo '}';
echo '}';
echo '}';
echo 'function loaddata3(){';
echo 'if(xmlHttp3.readyState==4){';
echo 'document.getElementById("f_img").innerHTML=\'\';';
echo '}';
echo '}';
echo 'function load(){';
echo 'xmlHttp=getHttpRequestObject(loaddata);';
echo 'if(xmlHttp!=null){';
echo 'var url="advhit.php";';
echo 'makeRequest(xmlHttp,url);';
echo '}else{';
echo 'alert("瀏覽程式不支援XMLHttpRequest物件!");';
echo '}';
echo '}';
echo 'function add(){';
echo 'xmlHttp2=getHttpRequestObject(loaddata2);';
echo 'if(xmlHttp2!=null){';
echo 'var url="advhit.php?i=1&id='.$id.'";';
echo 'var rand=parseInt(Math.random()*999999999);';
echo 'url=url+"&rand="+rand;';
echo 'makeRequest(xmlHttp2,url);';
echo '}else{';
echo 'alert("瀏覽程式不支援XMLHttpRequest物件!");';
echo '}';
echo '}';
?>
複製代碼
adv.css
#f_div{width:700px; height:200px; margin:0 auto; overflow:hidden;
}
#f_imgDiv{width:700px; height:200px; overflow:hidden;}
#f_img{filter:progid:DXImageTransform.Microsoft.Fade(Overlap=1.00); border:0;}
#f_infoDiv{width:700px;top:-16px;position:relative;background:#333;filter:Alpha(Opacity=70);-moz-opacity: 0.7; opacity: 0.7;}
#f_buttonDiv{width:700px; margin-right:1px; height:18px; overflow:hidden; text-align:left;color:#fff;}
#f_buttonDiv div,#f_buttonDiv .bg{
width:20px;height:18px; background:#333; float:right;
display:table-cell;
vertical-align:middle;
}
/*#f_buttonDiv .bg{width:94px;height:18px; background:#333; float:right; }*/
#f_buttonDiv a{
width:20px;height:18px !important;
float:right;
padding-top:5px;
color:#fff;
/*font-family:Arial, Helvetica, sans-serif;*/
font-family:serif;
font-size:12px;
text-align:center;
/*display:block;*/
overflow:hidden;
text-decoration:none;
/*position:absolute;*/
position:relative;
top:-2px;
}
*+html>body #f_buttonDiv a{top:-1px;}/*ie7*/
#f_buttonDiv div > a{top:-5px;}
#f_buttonDiv a:link,#f_buttonDiv a:visited,#f_buttonDiv a:active{color:#fff;}
#f_buttonDiv a:hover{color:#aaa;}
#f_buttonDiv a.on:link,#f_buttonDiv a.on:visited,#f_buttonDiv a.on:active,#f_buttonDiv a.on:hover{background:#99CC33;color:#000;}
#f_buttonDiv a.on:hover{background:#99CC33;}
複製代碼
歡迎光臨 TShopping (http://www.tshopping.com.tw/)
Powered by Discuz! X3.2