PHP Batch Process? Is this Possible?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post by donny »

cool thank you!
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP Batch Process? Is this Possible?

Post 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.
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post 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?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP Batch Process? Is this Possible?

Post 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.
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post by donny »

the template has a whole list of variables in it i don't think i can put it into a variable
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP Batch Process? Is this Possible?

Post by Celauran »

Want to post some code and we'll see what we can do?
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP Batch Process? Is this Possible?

Post 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.
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post 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
Last edited by donny on Tue Sep 02, 2014 4:38 pm, edited 1 time in total.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP Batch Process? Is this Possible?

Post 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.
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post 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
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post by donny »

what do you think function or class? also what do you mean by class?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP Batch Process? Is this Possible?

Post by Celauran »

donny wrote:what do you mean by class?
Classes and Objects
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP Batch Process? Is this Possible?

Post 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.
Post Reply