PHP Batch Process? Is this Possible?
Moderator: General Moderators
Re: PHP Batch Process? Is this Possible?
cool thank you!
Re: PHP Batch Process? Is this Possible?
will i be able to include a include into that for each?
also after i finish doing the foreach that transforms my orders. is it possible to create a csv on the same page?
so page loads
transforms all order numbers in the array
also posts the info into a database
then make a csv using the order numbers in the array
also after i finish doing the foreach that transforms my orders. is it possible to create a csv on the same page?
so page loads
transforms all order numbers in the array
also posts the info into a database
then make a csv using the order numbers in the array
Re: PHP Batch Process? Is this Possible?
I wouldn't include a file inside the foreach loop, but that's a small technicality. Everything you've described is absolutely possible.
Re: PHP Batch Process? Is this Possible?
i asked if i can include a file because i want to include the correct template file. i have multiple templates that take the same information and turn it into different variations. so i was going to include the correct template for each order. why do you say not to use include? should i use if statements instead?
Re: PHP Batch Process? Is this Possible?
Oh, I see. You could certainly read in a template, though it may be better to read in each template once, store it in a variable, and pass that into the function just to avoid opening the same file over and over.
Re: PHP Batch Process? Is this Possible?
the template has a whole list of variables in it i don't think i can put it into a variable
Re: PHP Batch Process? Is this Possible?
Want to post some code and we'll see what we can do?
Re: PHP Batch Process? Is this Possible?
its a whole bunch of stuff.
this is what i want done basically...
orders page - lists all orders with check boxes
process name phrase type
[x] peter rules yankees
[x] paul suck mets
[ ] maria move keepcalm
[ ] joe family custom
[x] tom suck mets
check off orders i want to process then click submit.. will go to a batch.php batch
batch.php page - this page will run each order checked off through the foreach
it will run order selected separately through a the appropriate transform script. there are multiple transform scripts. it will know which transform script to use from posted form data
this is what i want done basically...
orders page - lists all orders with check boxes
process name phrase type
[x] peter rules yankees
[x] paul suck mets
[ ] maria move keepcalm
[ ] joe family custom
[x] tom suck mets
check off orders i want to process then click submit.. will go to a batch.php batch
batch.php page - this page will run each order checked off through the foreach
Code: Select all
$script = $_POST['type'];
foreach ($orders_selected) {
run through transform $script.php
}
Re: PHP Batch Process? Is this Possible?
Right, I get that. My question is more whether the functionality in $script.php can be abstracted away into a function or class.
Re: PHP Batch Process? Is this Possible?
its got a whole bunch of stuff in it but heres an example
thanks a lot
Code: Select all
<?php
function randLetter()
{
$int = rand(0,23);
$a_z = "ABCDEFGHJKMNOPQRSTUVWXYZ";
$rand_letter = $a_z[$int];
return $rand_letter;
}
function randNumb()
{
$int = rand(0,8);
$a_z = "123456789";
$rand_letter = $a_z[$int];
return $rand_letter;
}
$random = randLetter() . randNumb() . $ordernumber . randNumb() . randLetter();
$cid = str_pad(rand(1, 9999), 4, '0', STR_PAD_LEFT) . "\n";
$first_name = strtoupper($_POST["first_name"]);
$middle_name = strtoupper($_POST["middle_name"]);
$last_name = strtoupper($_POST["last_name"]);
$address = strtoupper($_POST["address"]);
$city = strtoupper($_POST["city"]);
if ($color == 'BL') {
$color_old = 'Blue';
} else if ($color == 'PU') {
$color_old = 'Purple';
}
else if ($color == 'GR') {
$color_old = 'Green';
}
else if ($color == 'YE') {
$color_old = 'Yellow';
}
else if ($color == 'RD') {
$color_old = 'Red';
}
else if ($color == 'WH') {
$color_old = 'White';
}
else if ($color == 'BB') {
$color_old = 'Baby Blue';
}
else if ($color == 'PK') {
$color_old = 'Pink';
}
Last edited by donny on Tue Sep 02, 2014 4:38 pm, edited 1 time in total.
Re: PHP Batch Process? Is this Possible?
And this is one of your $script.php processing pages mentioned above? You've got some abstraction in there already, which is good. It can be improved on some. Is this the whole file? What do you do with the changes you're making here? Is this included and another script finishes processing?
does the same thing.
Code: Select all
function randNumb() {
return rand(1, 9);
}Re: PHP Batch Process? Is this Possible?
this is a snippet of it. and yes this is one of the scripts.php pages . its for processing a form though i will update it to data from a db .. that is not the whole file but most of it , i insert these changes into a database all in the same script
Re: PHP Batch Process? Is this Possible?
what do you think function or class? also what do you mean by class?
Re: PHP Batch Process? Is this Possible?
Classes and Objectsdonny wrote:what do you mean by class?
Re: PHP Batch Process? Is this Possible?
Which is the right approach to use here really depends on how much functionality exists in each of these processing scripts, how much they have in common, etc. I'm a big fan of OOP, code reuse, and keeping things DRY.