-2

出价和出价由 $bid,$bid1,$bid2 定义。它们需要每 1 秒刷新一次,它们位于我已经预定义的文本字段中。我可以在选择时输入价格,但我如何真正让它们焕然一新?

继承人的代码:

开始.php

<?php
session_start();
$timestamp=time();set_time_limit (0);
echo 'Welcome to trade page <br>';

$_SESSION['u'] = 'seyant';
$_SESSION['p']   = 'se5an123';
$_SESSION['q']   = 'eurates';

$url  = "http://webrates.truefx.com/rates/connect.html?c=EUR/USD&f=csv&s=n";
$url1 = "http://webrates.truefx.com/rates/connect.html?c=USD/JPY&f=csv&s=n";
$url2 = "http://webrates.truefx.com/rates/connect.html?c=USD/CAD&f=csv&s=n";
$url3 = "http://webrates.truefx.com/rates/connect.html?c=EUR/JPY&f=csv&s=n";
$url4 = "http://webrates.truefx.com/rates/connect.html?c=EUR/CHF&f=csv&s=n";
$url5 = "http://webrates.truefx.com/rates/connect.html?c=GBP/USD&f=csv&s=n";
$url6 = "http://webrates.truefx.com/rates/connect.html?c=AUD/USD&f=csv&s=n";
$url7 = "http://webrates.truefx.com/rates/connect.html?c=USD/CHF&f=csv&s=n";
 // create curl resource 
    $ch = curl_init(); 

    // set url 
    curl_setopt($ch, CURLOPT_URL, $url); 

    //return the transfer as a string 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    // $output contains the output string 
    $output = curl_exec($ch); 


    // close curl resource to free up system resources 
    curl_close($ch);

       $ch = curl_init(); 

    // set url 
    curl_setopt($ch, CURLOPT_URL, $url1); 

    //return the transfer as a string 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    // $output contains the output string 
    $output1 = curl_exec($ch); 


    // close curl resource to free up system resources 
    curl_close($ch);

               $ch = curl_init(); 

    // set url 
    curl_setopt($ch, CURLOPT_URL, $url2); 

    //return the transfer as a string 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    // $output contains the output string 
    $output2 = curl_exec($ch); 




    // close curl resource to free up system resources 
    curl_close($ch);

               $ch = curl_init(); 

    // set url 
    curl_setopt($ch, CURLOPT_URL, $url3); 

    //return the transfer as a string 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    // $output contains the output string 
    $output3 = curl_exec($ch); 



    // close curl resource to free up system resources 
    curl_close($ch);

               $ch = curl_init(); 

    // set url 
    curl_setopt($ch, CURLOPT_URL, $url4); 

    //return the transfer as a string 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    // $output contains the output string 
    $output4 = curl_exec($ch); 



    // close curl resource to free up system resources 
    curl_close($ch);

               $ch = curl_init(); 

    // set url 
    curl_setopt($ch, CURLOPT_URL, $url5); 

    //return the transfer as a string 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    // $output contains the output string 
    $output5 = curl_exec($ch); 



    // close curl resource to free up system resources 
    curl_close($ch);

               $ch = curl_init(); 

    // set url 
    curl_setopt($ch, CURLOPT_URL, $url6); 

    //return the transfer as a string 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    // $output contains the output string 
    $output6 = curl_exec($ch); 



    // close curl resource to free up system resources 
    curl_close($ch);

               $ch = curl_init(); 

    // set url 
    curl_setopt($ch, CURLOPT_URL, $url7); 

    //return the transfer as a string 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    // $output contains the output string 
    $output7 = curl_exec($ch); 



    // close curl resource to free up system resources 
    curl_close($ch);

// Example 1

$frag = explode(",", $output);

//echo $frag[2];
//echo $frag[3];
// echo'<br/>';
//echo $frag[4];
//echo $frag[5];
 //echo'<br/>';
echo'<br/>';
$bid = $frag[2].$frag[3];
Echo 'EUR/USD Bid '.$bid;
echo'<br/>';
$bid1 = $frag[4].$frag[5];
Echo 'EUR/USD Offer '.$bid1;
 echo'<br/>';

$frag1 = explode(",", $output1);

//echo $frag[2];
//echo $frag[3];
 // echo'<br/>';
//echo $frag[4];
//echo $frag[5];
 //echo'<br/>';
 $bid2 = $frag1[2].$frag1[3];

Echo 'USD/JPY Bid '.$bid2;//Bid
echo'<br/>';
$bid3 = $frag1[4].$frag1[5];
Echo 'USD/JPY Offer '.$bid3;//Offer
echo'<br/>';

$frag2 = explode(",", $output2);

//echo $frag[2];
//echo $frag[3];
// echo'<br/>';
//echo $frag[4];
//echo $frag[5];
//echo'<br/>';
$bid4 = $frag2[2].$frag2[3];
Echo 'USD/CAD Bid '.$bid4;//Bid
echo'<br/>';
$bid5 = $frag2[4].$frag2[5];
Echo 'USD/CAD Offer '.$bid5;//Offer
echo'<br/>';


$frag3 = explode(",", $output3);

 //echo $frag[2];
 //echo $frag[3];
 // echo'<br/>';
 //echo $frag[4];
//echo $frag[5];
  //echo'<br/>';
$bid6 = $frag3[2].$frag3[3];
 Echo 'EUR/JPY Bid '.$bid6;//BID
echo'<br/>';
$bid7 = $frag3[4].$frag[5];
 Echo 'EUR/JPY Offer '.$bid7;//OFFER
 echo'<br/>';
$frag4 = explode(",", $output4);

 //echo $frag[2];
 //echo $frag[3];
// echo'<br/>';
//echo $frag[4];
//echo $frag[5];
//echo'<br/>';
$bid8 = $frag4[2].$frag4[3];
Echo 'EUR/CHF Bid '.$bid8;
echo'<br/>';
$bid9 = $frag4[4].$frag4[5];
Echo 'EUR/CHF Offer '.$bid9;
 echo'<br/>';
 $frag5 = explode(",", $output5);

 //echo $frag[2];
 //echo $frag[3];
// echo'<br/>';
//echo $frag[4];
//echo $frag[5];
//echo'<br/>';
$bid10 = $frag5[2].$frag5[3];
Echo 'GBP/USD Bid '.$bid10;
echo'<br/>';
$bid11 = $frag5[4].$frag5[5];
Echo 'GBP/USD Offer '.$bid11;
echo'<br/>';
$frag6 = explode(",", $output6);

//echo $frag[2];
 //echo $frag[3];
 // echo'<br/>';
//echo $frag[4];
//echo $frag[5];
 //echo'<br/>';
  $bid12 = $frag6[2].$frag6[3];
Echo 'AUD/USD Bid '.$bid12;
echo'<br/>';
$bid13 = $frag6[4].$frag6[5];
 Echo 'AUD/USD Offer '.$bid13;
 echo'<br/>';
$frag7 = explode(",", $output7);

 //echo $frag[2];
//echo $frag[3];
// echo'<br/>';
//echo $frag[4];
//echo $frag[5];
  //echo'<br/>';
 $bid14 = $frag7[2].$frag7[3];
 Echo 'USD/CHF Bid '.$bid14;
 echo'<br/>';
 $bid15 = $frag7[4].$frag7[5];
Echo 'USD/CHF Offer '.$bid15;

include 'priceadder.php';



 ?>
<html>
     <head>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script>               
        $(document).ready(function() {
     $("#bid16").load("start.php");
             var refreshId = setInterval(function() {
             $("#bid16").load("http://webrates.truefx.com/rates/connect.html?c=EUR/USD,USD/JPY,USD/CAD,EUR/JPY,EUR/CHF,GBP/USD,AUD/USD,USD/CHF&f=csv&s=n");
             }, 500);
             $.ajaxSetup({ cache: false });
          });
      </script>
    </head>
  <body>

 <div id="bid16"></div>
 </body>
 </html>

Priceadder.php

 <?php
$timestamp=time();set_time_limit (0);

?>

<!DOCTYPE html>

<head><meta charset="UTF-8"></head>
<body>


<form action="price.php" method="get" id="myform"> 


<p>Symbol : <select name = "selection" id="selection">
<option value="Choose One">Choose One</option>
<option value="1">EUR/USD</option>
<option value="2">USD/JPY</option>
<option value="3">USD/CAD</option>
<option value="4">GBP/USD</option>
<option value="5">EUR/JPY</option>
<option value="6">EUR/CHF</option>
<option value="7">AUD/USD</option>
<option value="8">USD/CHF</option>

</select></p>
<p> Date : <input type="datetime" value="<?php echo date("Y-m-d ",$timestamp); ?>" name="date"/></p>
<p> Type : <input type="radio" name="type" value="buy">Buy 
<input type="radio" name="type" value="sell">Sell
<p> Size : <input type="number"pattern="[0-9]+([\.|,][0-9]+)?" step="0.01"name="size"/></p>
<p> Bid Price : <input id="bidprice" name="bidprice" type="text" value=""> 
Offer Price<input id="offerprice" name="offerprice" type="text" value=""> 
<p> Stop Loss : <input type="number"step="any" name="stoploss"/></p>
<p> Take Profit : <input type="number"step="any"name="takeprofit"/></p>

<input type="submit" value="Submit"/>
</form>



 <link rel="stylesheet" type="text/css" href=""> 

 <script type="text/javascript"> 

 window.onload=function() {  
  if (document.getElementById) { 
 document.getElementById("selection").onchange=function() { switchme(this); }  
  }  
 } 

  function switchme(SNewSel) { 

 var ind = SNewSel.selectedIndex; 
 var txt = document.getElementById('bidprice'); 
 var txt2 = document.getElementById('offerprice'); 
  switch (ind) { 
  case 1: // car purchase 
  txt.value = <?php echo json_encode($bid); ?>; 
   txt2.value = <?php echo json_encode($bid1); ?>; 
  break; 
  case 2: // other purchase 
  txt.value = <?php echo json_encode($bid2); ?>;
  txt2.value = <?php echo json_encode($bid3); ?>;

  break; 
 case 3: // other purchase 
 txt.value = <?php echo json_encode($bid4); ?> ;
  txt2.value = <?php echo json_encode($bid5); ?>;
 break; 
 default: 
 txt.value=''; 
 break; 
 } 
 } 
 </script> 


 </body>
 </html>
4

1 回答 1

0

首先,您需要在 start.php 中创建一个循环(while/for/foreach)。你做了很多次同样的事情。

然后对于您的问题,您需要使用 setInterval(callback, milliseconds) 函数:

http://www.w3schools.com/jsref/met_win_setinterval.asp

于 2013-07-31T07:49:44.380 回答