Reputation: 129
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
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.
Upvotes: 2
Views: 838
Reputation: 8616
You could use a CURL call.
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!
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 :)
Upvotes: 2
Reputation: 3866
How about using mysql_fetch_array() to get results in an array, then array_walk() to execute a function for each row?
http://php.net/manual/en/function.mysql-fetch-array.php
http://ca.php.net/manual/en/function.array-walk.php
Upvotes: 0