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 如何使用simulink建立一个永磁同步直线电机模型?
  • ¥30 天体光谱图的的绘制并得到星表
  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗