Page 2 of 7

Re: PHP Batch Process? Is this Possible?

Posted: Tue Sep 02, 2014 12:49 pm
by donny
cool thank you!

Re: PHP Batch Process? Is this Possible?

Posted: Tue Sep 02, 2014 1:05 pm
by donny
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

Re: PHP Batch Process? Is this Possible?

Posted: Tue Sep 02, 2014 1:14 pm
by Celauran
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?

Posted: Tue Sep 02, 2014 1:17 pm
by donny
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?

Posted: Tue Sep 02, 2014 1:20 pm
by Celauran
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?

Posted: Tue Sep 02, 2014 1:55 pm
by donny
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?

Posted: Tue Sep 02, 2014 1:58 pm
by Celauran
Want to post some code and we'll see what we can do?

Re: PHP Batch Process? Is this Possible?

Posted: Tue Sep 02, 2014 3:11 pm
by donny
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

Code: Select all

$script = $_POST['type'];
foreach ($orders_selected) {
        run through transform $script.php
}
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

Re: PHP Batch Process? Is this Possible?

Posted: Tue Sep 02, 2014 3:15 pm
by Celauran
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?

Posted: Tue Sep 02, 2014 3:42 pm
by donny
its got a whole bunch of stuff in it but heres an example

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';
}
thanks a lot

Re: PHP Batch Process? Is this Possible?

Posted: Tue Sep 02, 2014 3:48 pm
by Celauran
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?

Code: Select all

function randNumb() {
    return rand(1, 9);
}
does the same thing.

Re: PHP Batch Process? Is this Possible?

Posted: Tue Sep 02, 2014 3:54 pm
by donny
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?

Posted: Tue Sep 02, 2014 5:39 pm
by donny
what do you think function or class? also what do you mean by class?

Re: PHP Batch Process? Is this Possible?

Posted: Tue Sep 02, 2014 5:45 pm
by Celauran
donny wrote:what do you mean by class?
Classes and Objects

Re: PHP Batch Process? Is this Possible?

Posted: Tue Sep 02, 2014 5:47 pm
by Celauran
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.