[英]How to get information from Javascript to MySQL database using PHP?
[英]Rotating Text Using Javascript From Mysql Database
我正在尝试每5秒旋转一次表格单元格中的文本。 但是我需要从mysql数据库中获取数据。 这是我有使用html字幕的当前代码。 (代码在php中)。
echo "<marquee behavior=\Slide\" scrollamount=\"3\" direction=\"left\"height=\"100px\">";
echo "<a href=\"".$root."Index.php?page=diary\"><table><tr><td ><h2>--Upcoming Events--</h2></td></tr></table></a>";
echo "<table width=\"50px\"><tr><td></td></tr></table>";
for($count = 0; $count < $num_rows; $count++)
{
$row = mysql_fetch_array($result);
echo "<a href=\"".$root."Index.php?page=diary\"><table class=\"footer-inner\"><tr><td><p2>Event: ".$row['Title']."</p2></td><td width=\"10px\"></td>";
echo "<td><p2>Date: ".$row['Date']."</p2></td></tr>";
echo "<tr> <td><p2>Start Time: ".$row['Start Time']."</p2></td><td width=\"10px\"></td>";
echo "<td rowspan=\"3\"><p2>Details: ".$row['Text']."</p2></td></tr>";
echo "<tr><td><p2>End Time: ".$row['End Time']."</p2></td></tr>";
echo "<tr><td><p2>Location: ".$row['Location']."</p2></td></tr></table></a>";
echo "<table width=\"50px\"><tr><td></td></tr></table>";
}
echo "</marquee>";
我已经对此进行了一些研究,并且发现了如何每x秒旋转一次文本,代码如下:
<html>
<head>
<title>Rotating Text</title>
<script type="text/javascript">
var rotatingTextElement;
var rotatingText = new Array();
var ctr = 0;
function initRotateText() {
rotatingTextElement = document.getElementById("textToChange");
rotatingText[0] = rotatingTextElement.innerHTML; // store the content that's already on the page
rotatingText[1] = "Ten Reason to Buy Gumballs";
rotatingText[2] = "White House bla bla";
setInterval(rotateText, 5000);
}
function rotateText() {
ctr++;
if(ctr >= rotatingText.length) {
ctr = 0;
}
rotatingTextElement.innerHTML = rotatingText[ctr];
}
window.onload = initRotateText;
</script>
</head>
<body>
<span id="textToChange">New Release... Leopard</span>
</body>
</html>
但是,正如您看到的那样,这是一行,是的,我可以为表中的每个值执行此操作,对此我感到很满意。 但是我如何从mysql数据库中获得想要的东西并将其插入到数组中呢?
我在页面上使用php,我可以使用php获取我需要的所有信息,只需将其更改为Java脚本格式即可。
- - -编辑 - - -
是否可以在同一段代码中将php数组转换为javascript数组?
例如
var rotatingText = Arrayfuction('{php tag} echo $phparray; {php tag}');
在这里,检查一下:
我认为您的php代码将与此类似:
for($count = 0; $count < $num_rows; $count++)
{
texts.push( ".$row['Text'].");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.