TShopping

 找回密碼
 註冊
搜索
查看: 3285|回復: 0
打印 上一主題 下一主題

[問題] javascript php mysql輪播式廣告怎麼傳id值阿

[複製鏈接]
跳轉到指定樓層
1#
發表於 2010-6-12 22:43:25 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
 
Push to Facebook
大大您好,小弟有各移惑
小弟寫了各輪播式廣告
功能都正常,但是小弟想點擊廣告時,會傳會該廣告id給javascript再傳給PHP寫入MYSQL
小弟目前,已經可以傳id了,但是永遠都是抓最後一個id值,請懂的大大指導一下,我把程式貼下面

  1. <body onLoad="load()">
  2. </body>
  3.   <div align="center">{literal}<script type="text/javascript" src="adv.php"></script>{/literal}</div>
複製代碼


adv.php


  1. <?php
  2. include "global.php";
  3. echo 'document.write(\'<link rel="stylesheet" href="adv.css" type="text/css" />\');';
  4. echo 'var xmlHttp;';
  5. echo 'var xmlHttp2;';
  6. echo 'var xmlHttp3;';
  7. echo 'var imgWidth=700;';
  8. echo 'var imgHeight=200;';
  9. echo 'var _timeOut_=5000;';
  10. echo 'var timeOut=_timeOut_;';
  11. echo 'var timeOut2=_timeOut_/2;';
  12. echo 'var adNum=0; var target="_blank"; var button_Texton=\'#000000\'; var button_Textoff=\'#ffffff\';';
  13. echo 'var buttonLineOn="#99CC33"; var buttonLineOff="#333333";';
  14. echo 'var imgId=new Array();';
  15. echo 'var imgUrl=new Array();';
  16. echo 'var imgText=new Array();';
  17. echo 'var imgLink=new Array();';
  18. echo 'var imgTitle=new Array();';
  19. echo 'var imgAlt=new Array();';
  20. echo 'var ver=2; var firstTime=true;';
  21. echo 'document.write(\'<div id="ad_pic" class="block02">\');';
  22. echo 'document.write(\'<div id="f_div">\');';
  23. echo 'document.write(\'<div id="f_imgDiv">\');';

  24. $sql = @mysql_query("SELECT * FROM net_headeradv ORDER BY num LIMIT 8");
  25. $nowtime = mktime();
  26. while ($row = mysql_fetch_array($sql)) {
  27. $id = $row['id'];
  28. $num = $row['num'];
  29. $img = $row['img'];
  30. $url = $row['url'];
  31. $title = $row['title'];
  32. $starttime = $row['starttime'];
  33. $endtime = $row['endtime'];

  34. if ($nowtime >= $starttime && $endtime >= $nowtime) {
  35. echo 'imgId['.$num.'] = \''.$id.'\';';
  36. echo 'imgUrl['.$num.'] = \''.$img.'\';';   
  37. echo 'imgText['.$num.'] = \''.$num.'\';';
  38. echo 'imgLink['.$num.'] = \''.$url.'\';';
  39. echo 'imgTitle['.$num.'] = \''.$title.'\';';
  40. }
  41. }
  42. echo 'function b_change(n){';
  43. echo 'adNum=n; window.clearInterval(theTimer);  adNum=adNum-1; change();';
  44. echo '}';

  45. //計算載入幾張圖
  46. echo 'var count=0;';
  47. echo 'for (var i=0;i<imgUrl.length;i++) {';
  48. echo 'if( (imgUrl[i]!="") && (imgText[i]!="")&& (imgLink[i]!="")) {';
  49.   echo 'count++;';
  50. echo '} else {';
  51.   echo 'break;';
  52. echo '}';
  53. echo '}';
  54. //gcsse
  55. echo 'var each_width=Math.ceil((imgWidth-(count-1))/count);';
  56. echo 'var last_width=imgWidth-each_width*(count-1)-(count)+1;';

  57. echo 'function change(){';
  58. echo 'if(adNum<(imgUrl.length-1))adNum++;';
  59. echo 'else adNum=1;';
  60. echo 'theTimer=setTimeout("change()", timeOut);';
  61. echo 'document.getElementById("f_img").Id=imgId[adNum];';
  62. echo 'document.getElementById("f_img").src=imgUrl[adNum];';
  63. echo 'document.getElementById("f_img").title=imgTitle[adNum];';
  64. //var f_img=document.getElementById("f_img");
  65. //f_img.src=imgUrl[adNum];
  66. echo 'document.getElementById("f_imgLink").href=imgLink[adNum];';
  67. echo 'for (var i=1;i< count;i++){';
  68.    echo 'if (i !=adNum){';
  69.    echo 'document.getElementById(\'b\'+i).className="button";';
  70.   echo '}';
  71.   echo 'document.getElementById(\'b\'+adNum).className="on"; }';
  72. echo '}';
  73. 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>\');';
  74. echo 'document.write(\'</div>\');';
  75. echo 'document.write(\'<div id="f_infoDiv">\');';
  76. echo 'document.write(\'<div id="f_buttonDiv">\');';
  77. echo 'for (var i=count-1;i>=1;i--){';
  78. 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>\');';
  79. echo '}';
  80. echo 'document.write(\'</div>\');';
  81. echo 'document.write(\'</div>\');';
  82. echo 'document.write(\'</div>\');';
  83. echo 'document.write(\'</div>\'); change();';
  84. echo 'function getHttpRequestObject(handler){';
  85. echo 'var httpRequest=null;';
  86. echo 'if(window.XMLHttpRequest){';
  87.   echo 'httpRequest=new XMLHttpRequest();';
  88. echo '}else if(window.ActiveXObject){';
  89.   echo 'var msxmls=["Microsoft.XMLHttp","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp"];';
  90.   echo 'for(var i=0;i<msxmls.length;i++){';
  91.    echo 'try{';
  92.     echo 'httpRequest=new ActiveXObject(msxmls[i]);';
  93.     echo 'break;';
  94.    echo '}catch (e){';
  95.     echo 'return null;';
  96.    echo '}';
  97.   echo '}';
  98. echo '}';
  99. echo 'httpRequest.onreadystatechange=handler;';
  100. echo 'return httpRequest;';
  101. echo '}';
  102. echo 'function makeRequest(httpRequest,url){';
  103. echo 'httpRequest.open("GET",url,true);';
  104. echo 'httpRequest.send(null);';
  105. echo '}';
  106. echo 'function loaddata(){';
  107. echo 'if(xmlHttp.readyState==4){';
  108.   echo 'var xmlResult=xmlHttp.responseXML;';
  109.   echo 'var node=xmlResult.documentElement;';
  110.   echo 'if(node.getElementsByTagName("item")[0].firstChild.data!=0){';
  111.    echo 'document.getElementById("f_img").innerHTML="hit按鍵總共被按"+node.getElementsByTagName("item")[0].firstChild.data+"次!";';
  112.   echo '}';
  113. echo '}';
  114. echo '}';
  115. echo 'function loaddata2(){';
  116. echo 'if(xmlHttp2.readyState==4){';
  117.   echo 'var xmlResult2=xmlHttp2.responseXML;';
  118.   echo 'var node2=xmlResult2.documentElement;';
  119.   echo 'if(node2.getElementsByTagName("item")[0].firstChild.data!=0){';
  120.    echo 'document.getElementById("f_img").innerHTML="hit按鍵總共被按"+node2.getElementsByTagName("item")[0].firstChild.data+"次!";';
  121.   echo '}';
  122. echo '}';
  123. echo '}';
  124. echo 'function loaddata3(){';
  125. echo 'if(xmlHttp3.readyState==4){';
  126.   echo 'document.getElementById("f_img").innerHTML=\'\';';
  127. echo '}';
  128. echo '}';
  129. echo 'function load(){';
  130. echo 'xmlHttp=getHttpRequestObject(loaddata);';
  131. echo 'if(xmlHttp!=null){';
  132.   echo 'var url="advhit.php";';
  133.   echo 'makeRequest(xmlHttp,url);';
  134. echo '}else{';
  135.   echo 'alert("瀏覽程式不支援XMLHttpRequest物件!");';
  136. echo '}';
  137. echo '}';
  138. echo 'function add(){';
  139. echo 'xmlHttp2=getHttpRequestObject(loaddata2);';
  140. echo 'if(xmlHttp2!=null){';
  141.   echo 'var url="advhit.php?i=1&id='.$id.'";';
  142.   echo 'var rand=parseInt(Math.random()*999999999);';
  143.   echo 'url=url+"&rand="+rand;';
  144.   echo 'makeRequest(xmlHttp2,url);';
  145. echo '}else{';
  146.   echo 'alert("瀏覽程式不支援XMLHttpRequest物件!");';
  147. echo '}';
  148. echo '}';
  149. ?>
複製代碼


adv.css

  1. #f_div{width:700px; height:200px; margin:0 auto; overflow:hidden;
  2. }
  3. #f_imgDiv{width:700px; height:200px; overflow:hidden;}
  4. #f_img{filter:progid:DXImageTransform.Microsoft.Fade(Overlap=1.00); border:0;}
  5. #f_infoDiv{width:700px;top:-16px;position:relative;background:#333;filter:Alpha(Opacity=70);-moz-opacity: 0.7; opacity: 0.7;}
  6. #f_buttonDiv{width:700px; margin-right:1px; height:18px; overflow:hidden; text-align:left;color:#fff;}
  7. #f_buttonDiv div,#f_buttonDiv .bg{
  8. width:20px;height:18px; background:#333; float:right;
  9. display:table-cell;
  10. vertical-align:middle;
  11. }
  12. /*#f_buttonDiv .bg{width:94px;height:18px; background:#333; float:right; }*/
  13. #f_buttonDiv a{
  14. width:20px;height:18px !important;
  15. float:right;
  16. padding-top:5px;
  17. color:#fff;
  18. /*font-family:Arial, Helvetica, sans-serif;*/
  19. font-family:serif;
  20. font-size:12px;
  21. text-align:center;
  22. /*display:block;*/
  23. overflow:hidden;
  24. text-decoration:none;
  25. /*position:absolute;*/
  26. position:relative;
  27. top:-2px;
  28. }
  29. *+html>body #f_buttonDiv a{top:-1px;}/*ie7*/
  30. #f_buttonDiv div > a{top:-5px;}
  31. #f_buttonDiv a:link,#f_buttonDiv a:visited,#f_buttonDiv a:active{color:#fff;}
  32. #f_buttonDiv a:hover{color:#aaa;}
  33. #f_buttonDiv a.on:link,#f_buttonDiv a.on:visited,#f_buttonDiv a.on:active,#f_buttonDiv a.on:hover{background:#99CC33;color:#000;}
  34. #f_buttonDiv a.on:hover{background:#99CC33;}
複製代碼

 

臉書網友討論
*滑块验证:
您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-4-30 13:35 , Processed in 0.042077 second(s), 18 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表