PHP Batch Process? Is this Possible?
Moderator: General Moderators
PHP Batch Process? Is this Possible?
hello,
to start out ill give you guys an example and then what i want to do with it.
i have form where people input information. that goes into a database.
lets say they input their name, address and phone number.
so i have that info for everybody in a database
on my side i will have a page that i can select records in the database that i want to "process"
lets say each record is a name, so i select the names i want to process
after selecting them i will hit process and then i need each record in the database to be ran through a "transform" script that i have separately
basically i am transforming the information in the database to other variations and putting them into another database.
is it possible for me to make a batch file type code that will run each record i choose through my transform script separately.
this is just an example of what i am doing, its more complicated than this but this is the system i need to create somehow.
thanks a lot
to start out ill give you guys an example and then what i want to do with it.
i have form where people input information. that goes into a database.
lets say they input their name, address and phone number.
so i have that info for everybody in a database
on my side i will have a page that i can select records in the database that i want to "process"
lets say each record is a name, so i select the names i want to process
after selecting them i will hit process and then i need each record in the database to be ran through a "transform" script that i have separately
basically i am transforming the information in the database to other variations and putting them into another database.
is it possible for me to make a batch file type code that will run each record i choose through my transform script separately.
this is just an example of what i am doing, its more complicated than this but this is the system i need to create somehow.
thanks a lot
Re: PHP Batch Process? Is this Possible?
Sure it's possible, but have you considered whether it's worth all this work? Any reason you have to hand-pick the records? Why they can't just be "processed" immediately? What kind of transformation and into what kind of database?
Re: PHP Batch Process? Is this Possible?
its for orders that are paid. once a week i will check off all the orders that paid me. i don't want to do it automatically when they pay i want to have a page where i can do it myself incase i need to redo their order another time later on.
the transformation is just text to text. i make tshirts so i am inserting their name/phrase into my "t shirt templates" which are like random quotes or whatever. but i am taking their "phrase" from their order and putting it through the "transform" page that puts their information into it according to what tshirt they wanted to get.
example.. they place order my database looks like this
NAME/ORDERNUMBER , PHRASE, TYPE
john, suck, mets
billy, rule, yankees
pete, move, keep calm
after they pay i will select who paid... lets say all of them paid
it'll take all 3 of them to a transform page..
johns order will take him to the transform page using the mets transformation code
billys order will take him to the transform page using the yankees transformation code
pets order will take him to the transform page using the keep calm transformation code
mets transformation code is like this "The mets $phrase!"
yankees transformation code is "The yankees $phrase!"
keep calm transformation code is "Keep Calm and $phrase On!"
this is just an example.
so i want to be able to check off which orders are paid and have them go through a process page automatically one by one.
this process page will also store the info into a database. i do this so i can export to a csv easily. i am sure i can do this with PHP also but ill save that for another day, i don't mind using phpmyadmin for this.
the transformation is just text to text. i make tshirts so i am inserting their name/phrase into my "t shirt templates" which are like random quotes or whatever. but i am taking their "phrase" from their order and putting it through the "transform" page that puts their information into it according to what tshirt they wanted to get.
example.. they place order my database looks like this
NAME/ORDERNUMBER , PHRASE, TYPE
john, suck, mets
billy, rule, yankees
pete, move, keep calm
after they pay i will select who paid... lets say all of them paid
it'll take all 3 of them to a transform page..
johns order will take him to the transform page using the mets transformation code
billys order will take him to the transform page using the yankees transformation code
pets order will take him to the transform page using the keep calm transformation code
mets transformation code is like this "The mets $phrase!"
yankees transformation code is "The yankees $phrase!"
keep calm transformation code is "Keep Calm and $phrase On!"
this is just an example.
so i want to be able to check off which orders are paid and have them go through a process page automatically one by one.
this process page will also store the info into a database. i do this so i can export to a csv easily. i am sure i can do this with PHP also but ill save that for another day, i don't mind using phpmyadmin for this.
Last edited by donny on Tue Sep 02, 2014 10:56 am, edited 1 time in total.
Re: PHP Batch Process? Is this Possible?
Absolutely PHP can create CSV files. You shouldn't need to manually select things, either. A query based on payment date should work fine, for example. If you only want this to run once a week, you could set it up as a cron job.
Re: PHP Batch Process? Is this Possible?
i edited my post i added more information as example, i don't want it to do it automatically. i want to do it myself.
Re: PHP Batch Process? Is this Possible?
This line doesn't seem to fit with the rest of what you're saying, so forgive me if I'm misunderstanding anything here. None of this will actually be visible to the end user, right? You just need to process selected rows from one table and then redirect or display a flash message or something. Should be simple enough. Do you have the transform functionality already built and working? (Even for a single item, I mean. Not necessarily for batch processing.)it'll take all 3 of them to a transform page..
Re: PHP Batch Process? Is this Possible?
i shoudlntve said all 3 for an example lol but its the same thing.. no this is for my end the user won't see anything.. they place the order through my order system which is basically just a form that takes their name and phrase ...i need to select rows out of my db to be ran through a process page separately. thats it. if i select 10 rows (orders). i want each row to be ran through a process script that i have. all these pages are already made i do it manually. all i want to do is make a page that will take which ever rows i select and put it through this processing page...
Re: PHP Batch Process? Is this Possible?
also, this is just an example. there is a lot more to it. your probably thinking why don't i do this when they place the order. I'm sure there are easier and betters ways to do it, but for me, as long as it works the way i want it to, I'm happy. lol.
if i could write it out in my own code it'd look something like this
foreach(orders selected)
run through process page
process.php?ordernumber=xxx&template=xxx
repeat for each order selected
if i could write it out in my own code it'd look something like this
foreach(orders selected)
run through process page
process.php?ordernumber=xxx&template=xxx
repeat for each order selected
Last edited by donny on Tue Sep 02, 2014 11:25 am, edited 1 time in total.
Re: PHP Batch Process? Is this Possible?
So when you've submitted the form that selects the items, you could just iterate over the results and call the appropriate function on each, no? Doesn't sound like any pages are required as such, just a handful of functions or possibly even one depending on what's going on 'under the hood' if you will.
Re: PHP Batch Process? Is this Possible?
if i could write it out in my own code it'd look something like this
foreach(orders selected)
run through process page
process.php?ordernumber=xxx&template=xxx
repeat for each order selected
foreach(orders selected)
run through process page
process.php?ordernumber=xxx&template=xxx
repeat for each order selected
Re: PHP Batch Process? Is this Possible?
Pretty much what I'm suggesting, just remove the page from the equation.
Code: Select all
foreach ($orders_selected as $order) {
someFunction($order);
}Re: PHP Batch Process? Is this Possible?
this will run each order selected through the script separately? can you tell me how i go about getting $orders_selected from the database. on another page i am going to need to make a checkbox thing to view orders and to select them. i know how to view them but i don't know how to make a checkbox to select them and then post the checked ones to the next page or however it would go. and when you write someFunction i can earase that and just put the script between the foreach { } ?
Re: PHP Batch Process? Is this Possible?
Select your rows as you normally would for display. Inside the form, use something like
for the checkboxes.
When the form is submitted, $_POST['selected_orders'] will be an array of IDs. You can then iterate over that array and call whatever functions you need.
Code: Select all
<input name="selected_orders[]" type="checkbox" value="<?= $row['id']; ?>">When the form is submitted, $_POST['selected_orders'] will be an array of IDs. You can then iterate over that array and call whatever functions you need.
Depends what you mean by 'the script'. If you're planning on redirecting to another existing PHP page, that's not going to work. I'd move the functionality from your process.php into a function and call the function inside the foreach.donny wrote:when you write someFunction i can earase that and just put the script between the foreach { } ?
Re: PHP Batch Process? Is this Possible?
i gotcha, thanks a lot. how do i put selected orders into an array? thats what [] does?
Re: PHP Batch Process? Is this Possible?
Yes, exactly.donny wrote:how do i put selected orders into an array? thats what [] does?