以编程方式从PHP重定向到新的PAGES(新标签)

时间:2016-03-06 08:32:09

标签: php redirect

我需要从PHP重定向到新的标签页,用于记录集中的每个值。 基本上我需要点击具有特定值的URL才能将数据发布到thinkSpeak网站。只要我的表有记录,我就需要建立新的重定向。

<?php

$conc = mysql_connect("localhost","root","xxxxxxx");

if (!$conc) die("couldn't connect"  );

mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $con);
$re = mysql_query('SHOW VARIABLES LIKE "%character_set%";')or die(mysql_error());

mysql_query("SET NAMES utf8");
mysql_query("SET CHARACTER SET utf8");

$db_select = mysql_select_db("cccccc",$conc);



?>
<!-- STR_TO_DATE(asfaleia,'%m/%d/%Y')>'$curDate' AND -->
<!-- widget STARTS -->

<?php 
    $sql="SELECT  todo  FROM todo order by dleft asc";
    if ( !$data1 = mysql_query( $sql ) ) die( 'Could not SELECT, ' . mysql_error() );


    ?>

  <div style="float:right;">

    echo "<script type=\"text/javascript\">"


    <?php while($row1 = mysql_fetch_assoc($data1)) {

        ?>
    echo "  window.open('https://api.thingspeak.com/update?api_key=xxxxxxxxxxx&field1=" <?php .$row1['todo']. ?>."', '_blank')"
        <?php

    }
    $conc->close();
    ?>
  echo "  </script>";


</div>

这会给我一个错误

2 个答案:

答案 0 :(得分:0)

不幸的是,用PHP重定向打开新窗口是不可能的。打开新选项卡是PHP无法访问的浏览器功能。

答案 1 :(得分:0)

我知道这就是为什么我想用javascript做这件事 实际上我做到了,

$sql="SELECT  todo  FROM todo where dleft < 5 order by dleft asc";
if ( !$data1 = mysql_query( $sql ) ) die( 'Could not SELECT, ' . mysql_error() );
    echo "<span> ".$row1['todo']."  </span><br>";

 echo "<script>";
 echo "function sleep(ms) {";
  echo "  var unixtime_ms = new Date().getTime();";
  echo "  while(new Date().getTime() < unixtime_ms + ms) {}}";

  while($row1 = mysql_fetch_assoc($data1)) {
        $gamertag = strtolower($row1['todo']);
        $url = "https://api.thingspeak.com/update?api_key=xxxxxxxxxx&field1=".$gamertag.".";
        echo "window.open('$url');".PHP_EOL;
        echo "sleep(50);";
    }

 echo "</script>";
?>

现在的问题是thinkspeak不会更新所有内容,必须有延迟