doulao3078 2012-07-08 11:59
浏览 36
已采纳

在PHP中运行Javascript的问题

Good Afternoon, everyone.

I have an ongoing issue with the code below. I know that the Javascript/JQuery and JSON are working fine as demonstrated here - http://jsfiddle.net/Dvpmy/13/

I also know that the PHP works fine when my attempts at echoing the Javascript are omitted. However, when I combine everything, I seem to be experiencing issues. Chrome is flagging an 'Unexpected Identifier' and Firefox believes there is a missing closed parentheses after an argument. I am unable to find and remedy either.

<html>
<head>
<script type="text/javascript" src="/Portfolio/jquery.js"></script>
<?php


mysql_connect(localhost,"user","password");
@mysql_select_db("database") or die( "Unable to select database");
$query="SELECT * FROM quote WHERE view='yes'";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {

$ID=mysql_result($result,$i,"ID");
$EPIC=mysql_result($result,$i,"EPIC");

echo '<script type="text/javascript">';
echo'$.getJSON("http://query.yahooapis.com/v1/public/yql?     q=select%20*%20from%20yahoo.finance.historicaldata%20where%20symbol%20%3D%20%22DES%22%20and%20startDate%20%3D%20%222009-09-11%22%20and%20endDate%20%3D%20%222010-03-10%22&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=?", function(data) { console.log(data); var info = data.query.results.quote[0].Close; var date = data.query.results.quote[0].Date; var high = data.query.results.quote[0].High; $("div.quote").html("Test" $ID <br> $EPIC <br> high ); } );';
echo '</script>';


$i++;
}

?>
</head>
<body><div class='quote'></div></body></html>

I would like to apologise in advance if the solution is glaringly apparent. All assistance will be gratefully received.

Many thanks.

  • 写回答

1条回答 默认 最新

  • downloadTemp2014 2012-07-08 12:03
    关注

    What jumps out immediately is right at the end of the JavaScript block:

    $("div.quote").html("Test" $ID <br> $EPIC <br> high );
    

    Everything after "Test" is outside the quotes and would throw an error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置