为我的数据库mysql中的每一行调用一个php脚本

时间:2021-07-12 19:14:20

I'm sorry if it's a stupid question, but I don't now how to call a php script for every row from my table. I'm using mysql. (I will use PDO in the future, I know it's better). this is my "select" page ( where I select the rows that I want):

我很抱歉,如果这是一个愚蠢的问题,但我现在不知道如何从我的表中的每一行调用PHP脚本。我正在使用mysql。 (我将来会使用PDO,我知道它会更好)。这是我的“选择”页面(我选择了我想要的行):

<?php
include "util.php";
conn();
$SQL = "SELECT * FROM profiles where name='beatrice'"; //it's just an example
$result = mysql_query($SQL);

    while ($db_field = mysql_fetch_assoc($result)) {
                        $id= $db_field['id'] ;
                        $nome= strtolower($db_field['name']);
                        $cognome= strtolower($db_field['surname']);
                        $filenome= strtolower($db_field['filename']);
                        $cf= $db_field['cf'];
                        $dir1 = mb_substr($cf, 0, 8);
                        $dir=$id.$dir1;
                        mkdir('test/doc/'.$dir, 0777, TRUE);
                        mkdir('test/doc/'.$dir.'/foto', 0777, TRUE);
                        mkdir('test/doc/'.$dir.'/thumbnails', 0777, TRUE);
                        header('Location:renamer.php?dir='.$dir.'&nome='.$nome.'&filenome='.$filenome.'&id='.$id);
    }

    ?>

Header location doesn't work, so I'm searching for another way to do it.

标题位置不起作用,所以我正在寻找另一种方法来做到这一点。

2 个解决方案

#1


2  

You could use a CURL call.

您可以使用CURL调用。

OR just call a function to do what you want within the loop.

或者只是调用一个函数在循环中做你想做的事。

So just create a function (from the functionality within renamer.php) which takes the URL params as the arguments and off you go!

所以只需创建一个函数(来自renamer.php中的功能),它将URL参数作为参数,然后关闭!

If you REALLY need to do it in the background look into - http://php.net/manual/en/function.pcntl-fork.php - which will launch a new PHP process to execute something, if you go down this route it will get complicated and your task will need to report in some way so you know what has/has not been done :)

如果你真的需要做背景调查 - http://php.net/manual/en/function.pcntl-fork.php - 这将启动一个新的PHP进程来执行的东西,如果你走这条路线它会变得复杂,你的任务需要以某种方式报告,所以你知道有什么/没有做过:)

#2


0  

How about using mysql_fetch_array() to get results in an array, then array_walk() to execute a function for each row?

如何使用mysql_fetch_array()在数组中获取结果,然后使用array_walk()为每一行执行一个函数?

http://php.net/manual/en/function.mysql-fetch-array.php

http://ca.php.net/manual/en/function.array-walk.php

#1


2  

You could use a CURL call.

您可以使用CURL调用。

OR just call a function to do what you want within the loop.

或者只是调用一个函数在循环中做你想做的事。

So just create a function (from the functionality within renamer.php) which takes the URL params as the arguments and off you go!

所以只需创建一个函数(来自renamer.php中的功能),它将URL参数作为参数,然后关闭!

If you REALLY need to do it in the background look into - http://php.net/manual/en/function.pcntl-fork.php - which will launch a new PHP process to execute something, if you go down this route it will get complicated and your task will need to report in some way so you know what has/has not been done :)

如果你真的需要做背景调查 - http://php.net/manual/en/function.pcntl-fork.php - 这将启动一个新的PHP进程来执行的东西,如果你走这条路线它会变得复杂,你的任务需要以某种方式报告,所以你知道有什么/没有做过:)

#2


0  

How about using mysql_fetch_array() to get results in an array, then array_walk() to execute a function for each row?

如何使用mysql_fetch_array()在数组中获取结果,然后使用array_walk()为每一行执行一个函数?

http://php.net/manual/en/function.mysql-fetch-array.php

http://ca.php.net/manual/en/function.array-walk.php