热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

phpjavascripthtml,为什么这不起作用?-phpjavascripthtml,whydoesn'tthiswork?

hereismycode.Iamtryingtoconnecttomydatabaseandmakeajokeoftheday,soeverydayit

here is my code. I am trying to connect to my database and make a "joke of the day", so everyday it will show a different joke. I've looked through my code several times and can't find out why it's not working.

这是我的代码。我正在尝试连接到我的数据库并制作一个“当天的笑话”,所以每天都会显示一个不同的笑话。我已经多次查看了我的代码,但无法找出它无法正常工作的原因。

This is the Joke of the Day:

If anyone could help ASAP it would be very much appreciated! Thanks in advance

如果有人能尽快帮助,我们将非常感激!提前致谢

4 个解决方案

#1


2  

PHP has a getdate() function. See the documentation here. Use conditionals for the date in the PHP code instead of in Javascript, then simply "echo jokesarray[x]" where you need it.

PHP有一个getdate()函数。请参阅此处的文档。在PHP代码中使用条件而不是Javascript中的日期,然后只需“echo jokesarray [x]”即可。

#2


5  

First of all fix this:

首先解决这个问题:

var x=new Date();
var d(d.getDay());

to

var x = new Date();
var d  = x.getDay();

Second, everytime you have this document.write(jokesArray[1]; you are not closing it, like this:

第二,每次你有这个document.write(jokesArray [1];你没有关闭它,像这样:

document.write(jokesArray[1]);

and instead of doing that HUGE if statement block, just do this, which is the same.

而不是做那个巨大的if语句块,只是这样做,这是相同的。

document.write(jokesArray[d]);

#3


3  

All of your document.write's only have an open bracket, you need to close the bracket before the ;

你的所有document.write只有一个开放式支架,你需要先关闭支架;

EDIT: Also fix this, you have the date variable wrong

编辑:同样解决这个问题,你有错误的日期变量

var x=new Date();
var d(d.getDay());

needs to be

需要是

var x = new date();
var d = x.getDay();

Javascript is a funny language in the sense that something so simple will break without giving you a warning, try using firefox to debug Javascript.

Javascript是一种有趣的语言,在某种意义上说,如此简单的东西会在不给你警告的情况下破解,尝试使用firefox来调试Javascript。

Example:

Your Current Code:

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];
}

You need it like this:

你需要这样:

The Correct Code:

    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]);
}

Hope this helps

希望这可以帮助

#4


-1  

Ok i figured it out. It was a problem with my database. I had apostrophes and dashes in the values so it screwed up the rest of the code. Thanks anyways!

好吧,我想通了。这是我的数据库的问题。我在值中有撇号和破折号,因此它搞砸了其余的代码。不管怎么说,多谢拉!


推荐阅读
author-avatar
墙脚等红线_987
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有