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 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了