这是我的代码。我正在尝试连接到我的数据库并制作“今日笑话”,因此每天都会显示不同的笑话。我已经多次查看我的代码,但无法找出它为什么不起作用。
<div id="joke">
This is the Joke of the Day:
<script>
var jokesArray = new Array ();
<?php
$jokeid = 1;
$link = mysqli_connect("localhost","root","","nick-website-database") or die("Error " . mysqli_error($link));
$temp = mysqli_query($link, "SELECT * FROM `jokes`");
$i = 0;
while($joke = mysqli_fetch_array($temp)) {
echo "jokesArray[".$i."]='" . $joke["description"]."';" ;
$i++;
}
?>
var x=new Date();
var d(d.getDay());
if (d === 0) {
document.write(jokesArray[0];
}
else if (d === 1) {
document.write(jokesArray[1];
}
else if (d === 2) {
document.write(jokesArray[2];
}
else if (d === 3) {
document.write(jokesArray[3];
}
else if (d === 4) {
document.write(jokesArray[4];
}
else if (d === 5) {
document.write(jokesArray[5];
}
else if (d === 6) {
document.write(jokesArray[6];
}
</script>
</div>