dptt66700 2009-10-02 04:03
浏览 76
已采纳

在php中运行脚本,查找尚未在mysql中修改的项目

I have db with column named "link". Links have redirect urls, which I want to change. I have php script, which would take the link and gives me output as follows:

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

print_r($rez);

this is the output:

Array
(
    [0] => htp://www.otherdomain.com
)

how do I loop all items in my database, and run this script for each item. my db is called "apps" and table is called "items" and column containing urls is called "link" above php script is called getredirect.php

Also when I run script I need to run without the "&ID=123&otherstuff=whatever"

(htp supposed to be http... I can't add links per board rules)

  • 写回答

2条回答 默认 最新

  • doushi1957 2009-10-02 04:19
    关注

    how do I loop all items in my database, and run this script for each item

    Can you just do a simple select and put it in an array, and loop through it?

    $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);
    

    Not sure whether it helps, your question is kinda unclear to me.

    If you aren't sure of the output, you can put a print_r statement, i.e.,

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

    This would help you understand the PHP code clearer

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100