PHP Batch Process? Is this Possible?
Moderator: General Moderators
Re: PHP Batch Process? Is this Possible?
can you put my snippet of code into a class? i am reading about the classes and looking at examples but don't see how id do it.
Re: PHP Batch Process? Is this Possible?
also would i be able to have a progress bar indicating how many are left to do? lets say i am running 50 orders is there a way i can see how many its done and how many are left... or a bootstrap progress bar? or would this be a javascript thing?
Re: PHP Batch Process? Is this Possible?
Have you tried? Where did you get stuck?donny wrote:can you put my snippet of code into a class? i am reading about the classes and looking at examples but don't see how id do it.
I can help you design a class or classes for your processing scripts, but it would be helpful to know all the functionality beforehand.
Re: PHP Batch Process? Is this Possible?
In theory, yes it's possible. In practice, unless you're processing huge batches, there's probably no point.donny wrote:also would i be able to have a progress bar indicating how many are left to do? lets say i am running 50 orders is there a way i can see how many its done and how many are left... or a bootstrap progress bar? or would this be a javascript thing?
Re: PHP Batch Process? Is this Possible?
the snippet i posted has all the functionality in it, the actual script has all the same functionality but just more of them for more fields/variations. but all php functions that the script uses are included in the snippet.. all scripts have the same functionality, the differences are variations.
as for as trying to do the php class thing, every time i tried looking something up i got information on taking school classes for php lol and the ones i did find about the php function confused me. this is what i put together. am i on the right track? i don't know how to call/run the class function (if I'm even doing it right).. also instead of posting my code in each class function can i include it?
remember the coding in the classes are just examples.
thank you so much.
as for as trying to do the php class thing, every time i tried looking something up i got information on taking school classes for php lol and the ones i did find about the php function confused me. this is what i put together. am i on the right track? i don't know how to call/run the class function (if I'm even doing it right).. also instead of posting my code in each class function can i include it?
Code: Select all
<?php
//class A is script1.php
class A{
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';
}
} //class A end
//class B is script2.php
class B {
$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';
}
} //class B end
foreach ($orders_selected as $order) {
if ($type == 'script1') {
run class A
}
if ($type == 'script2') {
run class B
}
}
?>
thank you so much.
Re: PHP Batch Process? Is this Possible?
Based on the sample code you've provided, what's the difference in functionality between the two classes? I'm not seeing any, so let's stick to one class. What's happening with all these variables that are being declared? Where/how are they being used? That might be something we want as part of this class. Where do $ordernumber and $color come from?
Re: PHP Batch Process? Is this Possible?
everything is coming from a database.. i know i just used those as examples. the differences between the classes will be ones going into different databases and changing the database information to different variations....the scripts are taking form submitted data and changing it and then putting it into another database... forget about the codes in the classes because they work when i do it manually. i am not worried about them, they work fine right now. i just want to be able to just run these data into these scripts automatically thats all.
so using this new sample how can i make it run automatically
thanks a lot!!
so using this new sample how can i make it run automatically
Code: Select all
<?php
class A{
//CLASS A SCRIPT
}
class B {
//CLASS B SCRIPT
}
foreach ($orders_selected as $order) {
if ($type == 'script1') {
run class A
}
if ($type == 'script2') {
run class B
}
}
?>
thanks a lot!!
Re: PHP Batch Process? Is this Possible?
So I have set up two very basic classes based on the code snippets you provided. It abstracts away some repetitive functionality and saves you from having to pass around a ton of variables but at this stage both are admittedly of little use. Client especially is just a data transport object at present and offers no real benefit over the $_POST array. Each class is instantiated via the 'new' operator and by passing in the required arguments.
Code: Select all
<?php
class Order {
protected $color_map = [
'BL' => 'Blue',
'GR' => 'Green',
'PU' => 'Purple',
];
protected $cid;
protected $color;
protected $ordernumber;
protected $random;
public function __construct($ordernumber, $color) {
$this->ordernumber = $ordernumber;
$this->color = $color;
}
public function getOldColor($color) {
return $this->color_map[$color];
}
/**
* I don't know what cid or random represent, so don't know what else to call this
*/
public function init() {
$this->cid = $this->generateCid();
$this->random = $this->generateRandom();
}
protected function generateCid() {
return str_pad(rand(1, 9999), 4, '0', STR_PAD_LEFT);
}
protected function generateRandom() {
return $this->randLetter() . $this->randNumb() . $this->ordernumber . $this->randNumb() . $this->randLetter();
}
protected function randLetter() {
$int = rand(0,23);
$a_z = "ABCDEFGHJKMNOPQRSTUVWXYZ";
$rand_letter = $a_z[$int];
return $rand_letter;
}
protected function randNumb() {
return rand(1, 9);
}
}
class Client {
protected $first_name;
protected $middle_name;
protected $last_name;
protected $address;
protected $city;
public function __construct(array $data) {
$this->first_name = isset($data['first_name']) ? strtoupper($data['first_name']) : null;
$this->middle_name = isset($data['middle_name']) ? strtoupper($data['middle_name']) : null;
$this->last_name = isset($data['last_name']) ? strtoupper($data['last_name']) : null;
$this->address = isset($data['address']) ? strtoupper($data['address']) : null;
$this->city = isset($data['city']) ? strtoupper($data['city']) : null;
}
}
// The Order class requires an order number and a colour, so we'd create it as:
$order = new Order($ordernumber, $color);
// Want to set up $random and $cid, call the init method
$order->init();
// What was $random is now $order->random. Because that property is protected, it is only
// accessible within the class or classes extending it. Ditto $cid.
// The Client class requires an array of properties that are currently being populated via form
$client = new Client($_POST);Re: PHP Batch Process? Is this Possible?
Well, that does change things a little. Classes are typically used to group related properties and functionality and are generally each responsible for one thing (hence why Order and Client were separated out in the example above). Given your use case, at least with the information I have, maybe a few simple functions will provide all the abstraction you'll need here.donny wrote:everything is coming from a database.. i know i just used those as examples. the differences between the classes will be ones going into different databases and changing the database information to different variations....the scripts are taking form submitted data and changing it and then putting it into another database... forget about the codes in the classes because they work when i do it manually. i am not worried about them, they work fine right now. i just want to be able to just run these data into these scripts automatically thats all.
so using this new sample how can i make it run automatically
Re: PHP Batch Process? Is this Possible?
wow thanks a lot . that looks really cool and really confusing!! lol i guess thats what the right way of doing things looks like! i can manage to replicate the rest of my code into functions like you did . but now how would i run the foreach code? i will have the selected orders coming in as an array. and i will also have another variables lets call it "type" which will tell the foreach which class needs to be used
Re: PHP Batch Process? Is this Possible?
That was part of what I couldn't work out based on the information I had. You're iterating over an array, but you're also referencing $_POST. Unless all the orders in that array belong to the same person, I foresee some problems there. Type also isn't clear. Maybe it needs to be a separate class, maybe it can extend an existing class, maybe it's nothing more than a parameter.
Re: PHP Batch Process? Is this Possible?
i was using post because the snippet was from a form processing page from when i was doing it manually... this batch will be pulling form data from a database.
Re: PHP Batch Process? Is this Possible?
Ok so basically i thank you very much for helping me and taking time to write a lot of code for me but i don't think this is going to work for me.
I have a order form. each order generates a unique order number.
i have the customer fill out data in the form. data being name, address, just basic information.
this information is posted into a database when they're done.
1 form or 10 of these data forms can be filled out for each order.
the data is stored in a database in rows, all of them have the same order number and all data submissions have different unique numbers stored under a column called formnumber
so my database looks like this
ordernumber formnumber info1 info2 info3 info4 type
001 101 data data data data 1
001 102 data data data data 2
001 103 data data data data 1
002 104 data data data data 1
003 105 data data data data 2
004 106 data data data data 2
004 107 data data data data 2
005 108 data data data data 1
005 109 data data data data 1
there are 5 orders in my database. with 9 form data submissions. info1-info4 and type are form submission data.
all of this will be on my end, not the client end. this will be like a "admin page"
Basically all I need to make is a page that will list orders from my database, by order number
it will list each one with a checkbox, the value of the checkbox will be the order number.
order
[] 001
[] 002
[] 003
[] 004
etc
i want to select orders to be "processed"
order
[] 001
[x] 002
[] 003
[x] 004
i select orders 002 and 004 to be processed.
now i need page that will take orders 002, and 004 and process them.
by process them i mean take all the form data submissions and put them through a script.
so if i am processing orders 002, and 004 in other words i am processing formnumbers (submissions) 104,106 and 107
so i need to take form submissions 104,106, and 107 and run them through a script.
i need to pull their info1 info2 info3 and info4 information from the database and put them into variables.
and process them with my "script". now this "script" is very simple. all it does is take information and switch it around a bunch of ways. like make stuff capitals and lowercases and add random numbers to them. nothing crazy. it works fine how it is right now.
i use the script manually and what i mean by that is i have a form, i refill the form fields out with the form submitted information and i click submit. it takes that info and puts it through the script. what i want to do is have my customers fill out their information in the form. and it'll get stored as "Raw data" lets call it. i want to be able to take that data later on and run it through my script, just as if it was me re-typing in the information myself into my form that does it manually. this code will take their information and POST it into this script and run it automatically. separately for each formsubmissions.
why you ask? there are easier ways you say? well this is what i need done, with all due respect i don't care if theres an easier way. this is how i need it to be.
so back to what i need done. we are processing orders 002, and 004 to be processed.
so we are going to take the form submissions for those orders (104, 106 and 107) and run each of their data separately through my script.
basically as if it were a robot retyping this information into another form and clicking submit. 3 different times, one time for each separately. thats what i need done. and the from processing page will be this "script".
now heres the thing, i have more than 1 "script" i have 2 right now and maybe more in the future.
so this processing page i will want it to be able to select which script the data gets ran through. in my database i have a column "type" in there it says 1 or 2. one day it might say 4 or 5. point is, i am going to eventually have more scripts that i need data ran through.
so in english this is what this page should be doing.
orders 002 and 004 selected for processing.
look up which formnumbers are under those orders.
formnumbers 104,106 and 107 are under those orders.
good. now run them through the right script.
run 104's data through script number 1
get info1, info2, info3, and info4 where formnumber=104
good, now run it through script 1
done!
run 106's data through script number 2
get info1, info2, info3, and info4 where formnumber=106
good, now run it through script 2
done!
run 107's data through script number 2.
get info1, info2, info3, and info4 where formnumber=107
good, now run it through script 2
done!
so again. i basically need to make a robot that can take a list of order numbers, look up the formnumbers for each order number. then i need it to look up each formnumbers data, copy it, put it into variables, whatever it needs to do and run it through script 1 or script 2 depending on which one it says to under the type column in the database.
or pretend me doing it. i have a form with fields for data1 , data2, data3, and data4. i look up each persons submitted data and copy it into the right field. i hit submit. Done!!!! i have 2 forms with the same fields, one for each script that i have. so if i need it ran through script 1 i will use form 1 if i need it ran through script 2 i will use form 2. only differences is the forms action.
i really appreciate all the help i am getting from you and everybody here!!
i hope this makes it easier to understand what i am trying to do and i hope it can be done!!
I have a order form. each order generates a unique order number.
i have the customer fill out data in the form. data being name, address, just basic information.
this information is posted into a database when they're done.
1 form or 10 of these data forms can be filled out for each order.
the data is stored in a database in rows, all of them have the same order number and all data submissions have different unique numbers stored under a column called formnumber
so my database looks like this
ordernumber formnumber info1 info2 info3 info4 type
001 101 data data data data 1
001 102 data data data data 2
001 103 data data data data 1
002 104 data data data data 1
003 105 data data data data 2
004 106 data data data data 2
004 107 data data data data 2
005 108 data data data data 1
005 109 data data data data 1
there are 5 orders in my database. with 9 form data submissions. info1-info4 and type are form submission data.
all of this will be on my end, not the client end. this will be like a "admin page"
Basically all I need to make is a page that will list orders from my database, by order number
it will list each one with a checkbox, the value of the checkbox will be the order number.
order
[] 001
[] 002
[] 003
[] 004
etc
i want to select orders to be "processed"
order
[] 001
[x] 002
[] 003
[x] 004
i select orders 002 and 004 to be processed.
now i need page that will take orders 002, and 004 and process them.
by process them i mean take all the form data submissions and put them through a script.
so if i am processing orders 002, and 004 in other words i am processing formnumbers (submissions) 104,106 and 107
so i need to take form submissions 104,106, and 107 and run them through a script.
i need to pull their info1 info2 info3 and info4 information from the database and put them into variables.
and process them with my "script". now this "script" is very simple. all it does is take information and switch it around a bunch of ways. like make stuff capitals and lowercases and add random numbers to them. nothing crazy. it works fine how it is right now.
i use the script manually and what i mean by that is i have a form, i refill the form fields out with the form submitted information and i click submit. it takes that info and puts it through the script. what i want to do is have my customers fill out their information in the form. and it'll get stored as "Raw data" lets call it. i want to be able to take that data later on and run it through my script, just as if it was me re-typing in the information myself into my form that does it manually. this code will take their information and POST it into this script and run it automatically. separately for each formsubmissions.
why you ask? there are easier ways you say? well this is what i need done, with all due respect i don't care if theres an easier way. this is how i need it to be.
so back to what i need done. we are processing orders 002, and 004 to be processed.
so we are going to take the form submissions for those orders (104, 106 and 107) and run each of their data separately through my script.
basically as if it were a robot retyping this information into another form and clicking submit. 3 different times, one time for each separately. thats what i need done. and the from processing page will be this "script".
now heres the thing, i have more than 1 "script" i have 2 right now and maybe more in the future.
so this processing page i will want it to be able to select which script the data gets ran through. in my database i have a column "type" in there it says 1 or 2. one day it might say 4 or 5. point is, i am going to eventually have more scripts that i need data ran through.
so in english this is what this page should be doing.
orders 002 and 004 selected for processing.
look up which formnumbers are under those orders.
formnumbers 104,106 and 107 are under those orders.
good. now run them through the right script.
run 104's data through script number 1
get info1, info2, info3, and info4 where formnumber=104
good, now run it through script 1
done!
run 106's data through script number 2
get info1, info2, info3, and info4 where formnumber=106
good, now run it through script 2
done!
run 107's data through script number 2.
get info1, info2, info3, and info4 where formnumber=107
good, now run it through script 2
done!
so again. i basically need to make a robot that can take a list of order numbers, look up the formnumbers for each order number. then i need it to look up each formnumbers data, copy it, put it into variables, whatever it needs to do and run it through script 1 or script 2 depending on which one it says to under the type column in the database.
or pretend me doing it. i have a form with fields for data1 , data2, data3, and data4. i look up each persons submitted data and copy it into the right field. i hit submit. Done!!!! i have 2 forms with the same fields, one for each script that i have. so if i need it ran through script 1 i will use form 1 if i need it ran through script 2 i will use form 2. only differences is the forms action.
i really appreciate all the help i am getting from you and everybody here!!
i hope this makes it easier to understand what i am trying to do and i hope it can be done!!
Re: PHP Batch Process? Is this Possible?
Hi there.
With all due respect... You are asking people to develop an inefficient system (process) which will inevitably cause you complications in the long run.
Celauran is offering you great advice to be able to develop a fully expandable system. Take that advice and use it buddy to its best ability.
Best wishes.
With all due respect... You are asking people to develop an inefficient system (process) which will inevitably cause you complications in the long run.
You will struggle getting someone to help you design AND code a flawed system design. My advice to you is this: understand that although you may only have 3 products, eventually, you may want to increase this product offering, require additional information submitted and by creating this system you are going to cause yourself many headaches.with all due respect i don't care if theres an easier way. this is how i need it to be.
Celauran is offering you great advice to be able to develop a fully expandable system. Take that advice and use it buddy to its best ability.
Best wishes.
Re: PHP Batch Process? Is this Possible?
thanks and i get that completely and understand completely. but i know that this site isn't going to do crazy traffic because i sell tshirts to friends and family. i am not planning to be the next tommy hillfiger, it is not for a huge store. it is very small.
and when i say this is how it needs to be, it doesn't NEED to be that way. that is what will work for me. i want something easy, flawed or not flawed. if it works, thats fine for me. i don't want people to spend time writing code like its going to be for macys or something.
i didn't mean to come off as rude when i said that either so you defiantly mis understood me. thanks for your input though. i am not asking for someone to do the whole thing for me. i do need help to be put in the right direction though. and if someone helps me code one for 3 products i will be able to expand onto it myself. i do have some knowledge.
and when i say this is how it needs to be, it doesn't NEED to be that way. that is what will work for me. i want something easy, flawed or not flawed. if it works, thats fine for me. i don't want people to spend time writing code like its going to be for macys or something.
i didn't mean to come off as rude when i said that either so you defiantly mis understood me. thanks for your input though. i am not asking for someone to do the whole thing for me. i do need help to be put in the right direction though. and if someone helps me code one for 3 products i will be able to expand onto it myself. i do have some knowledge.