Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中为mysql中尚未修改的项目运行脚本_Php_Mysql_Loops - Fatal编程技术网

在php中为mysql中尚未修改的项目运行脚本

在php中为mysql中尚未修改的项目运行脚本,php,mysql,loops,Php,Mysql,Loops,我有一个db,列名为link。 链接有重定向URL,我想更改。 我有一个php脚本,它将获取链接并提供如下输出: $redo = get_redirect('htp://www.mydomain.com/long/url/here&ID=123'); print_r($rez); 这是输出: Array ( [0] => htp://www.otherdomain.com ) 如何循环数据库中的所有项目,并为每个项目运行此脚本。 my db称为apps,表称为item

我有一个db,列名为link。 链接有重定向URL,我想更改。 我有一个php脚本,它将获取链接并提供如下输出:

$redo = get_redirect('htp://www.mydomain.com/long/url/here&ID=123');

print_r($rez);
这是输出:

Array
(
    [0] => htp://www.otherdomain.com
)
如何循环数据库中的所有项目,并为每个项目运行此脚本。 my db称为apps,表称为items,包含URL的列称为link,php脚本称为getredirect.php

另外,当我运行脚本时,我需要在没有&ID=123&otherstuff=whatever的情况下运行


htp应该是http。。。我无法按线路板规则添加链接

看起来您的get_redirect只是一个连接到DB并获取给定URL的重定向URL的函数

您可以编写SQL查询以获取所有项目的重定向:

Select urls,link from apps.items;
您还可以修改函数defention,使其需要多个项并返回相应的重定向:

function get_multiple_redirect($aItems){

$SQL = "Select urls,link from apps.items WHERE url IN ('" . implode("','",$aItems) ."')";
#... add mysql calls here


print_r( get_multiple_redirect(array("http://abc","http://def")) );
}
如何循环数据库中的所有项目,并为每个项目运行此脚本

你能做一个简单的选择并把它放在一个数组中,然后循环通过它吗

$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT link FROM apps");

while($row = mysql_fetch_array($result))
  {
      $url=implode('&', $row[0]);
      include 'getredirect.php?url='.$url;

  }

mysql_close($con);
我不确定这是否有帮助,你的问题对我来说有点不清楚

如果您对输出不确定,可以放入print\r语句,即

while($row = mysql_fetch_array($result))
  {
      print_r($row);
      include 'getredirect.php?url='.$url;

  }

这将帮助您更清楚地理解PHP代码

get redirect是指向实际url并给出最终目的地的实际脚本;它在哪里将修改后的url插入回数据库?试图弄清楚答案:我在我的专栏www.something.com/whater/&ide=123 www.something.com/whater/&ide=456 www.something.com/whater/&ide=789等中有这20个项目,我想使用我的getredirect.php循环它们,并用它们的最终目标URL将它们插入回去,比如www.where.com www.somebodyelse.com www.otherplace.com谢谢,我认为你的解决方案非常接近。当我运行脚本时,它看起来好像在做什么,但不知道是什么,并得到20次警告:内爆[function.in爆]:传入的参数无效…第10行???它看起来好像在做什么,但不知道什么,也许你应该阅读php中的数据库访问?$url=in爆'&',$row[0];上面的行返回字符串而不是数组,所以我将其更改为$url=$row[0];但现在如何将其插入数据库?我是否需要使用insert或update等,或者他们更容易做到这一点?当我添加以下内容时,我会更加接近:$newurl=include'$sql_update=更新项目集newlink='$newurl';mysql\u查询$sql\u更新或diemysql\u错误;var_dump$newurl;我在newlink列中得到了1,vardump显示了这个数组[0]=>int1