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

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 »

You've got foreach loops inside foreach loops all to fetch data you've already got. Is there any reason it needs to be like that? What, ultimately, are you doing with the data? Directly operating on each row from the initial query, what data do you need that you wouldn't have?
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post by donny »

your right that will work. I'm new remember!!! lol cool stuff though!

now the question is!! I'm going to run all this data through a foreach again that will include the code. what will this look like?
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 »

You'll have to be more specific than 'the code'. The processing script we looked at the other day? Some field in a database?
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post by donny »

Code: Select all

foreach (each array formnumber data seperatly) {
$data1e = strtoupper($data1fromarray);
$data2e = strtoupper($data2fromarray);
$data3e = strtoupper($data3fromarray);
$data4e = strtoupper($data4fromaray);
$type = $type_from_array;

$rawsql = "INSERT INTO edited
	   (ordernumber, formnumber, data1e, data2e, data3e, data4e)
	  VALUES('$ordernumber','$formnumber','$data1e','$data2e','$data3e','$data4e')";
mysql_query($rawsql);
}
it'll look something like this.
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 »

Instead of executing your query inside your loop, though, build it up inside the loop and run one query at the end.
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post by donny »

how can i do that? the script will be changing the variables for all the different formnumber submissions thats getting passed through it.
also can you show me how to setup the foreach to go through the array we just made? i also need to know how to call the data out of them too
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post by donny »

put all edited results into an array? query the array after?
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 »

This
donny wrote:

Code: Select all

foreach (each array formnumber data seperatly) {
$data1e = strtoupper($data1fromarray);
$data2e = strtoupper($data2fromarray);
$data3e = strtoupper($data3fromarray);
$data4e = strtoupper($data4fromaray);
$type = $type_from_array;

$rawsql = "INSERT INTO edited
	   (ordernumber, formnumber, data1e, data2e, data3e, data4e)
	  VALUES('$ordernumber','$formnumber','$data1e','$data2e','$data3e','$data4e')";
mysql_query($rawsql);
}
becomes this

Code: Select all

$query = "SELECT `ordernumber`, `form number`, UPPER(`info1`), UPPER(`info2`), UPPER(`info3`), UPPER(`info4`), `type` FROM `rawdata` WHERE `ordernumber` IN ($list)";
$results = mysql_query($query);

$values = array();
while ($row = mysql_fetch_assoc($results)) {
	$values[] = "('{$row['ordernumber']}', '{$row['formnumber']}', '{$row['info1']}', '{$row['info2']}', '{$row['info3']}', '{$row['info4']}')";
}

$query = "INSERT INTO `edited` (ordernumber, formnumber, data1e, data2e, data3e, data4e) VALUES ";
$query .= implode(',', $values);
mysql_query($query);
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 »

Although, looking at it, you're just taking values from one table and copying them directly to another table. What am I missing?
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post by donny »

theres more to it than that, i just put that up there for the example.
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post by donny »

forget about the code thats being ran and forget about the mysql thats just complicating things...

i need to run the array $ordercid through this... i need set variables based on the information in each array

Code: Select all

foreach (each array formnumber data seperatly) {

//set variables
$data1 = $GET_DATA1_FROM_ARRAY
$data2 = $GET_DATA2_FROM_ARRAY
$data3 = $GET_DATA3_FROM_ARRAY
$data4 = $GET_DATA4_FROM_ARRAY

//MY CODING WILL BE HERE

}
all i need is to run each array through this foreach. the variables being set need to be updated for each array that is going through it.

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

Re: PHP Batch Process? Is this Possible?

Post by donny »

Code: Select all

Array
(
    [ORDERNUMBER] => Array
        (
            [0] => Array
                (
                    [0] => dataforinfo1
                    [info1] => dataforinfo1
                    [1] => dataforinfo2
                    [info2] => dataforinfo2
                    [2] => dataforinfo3
                    [info3] => dataforinfo3
                    [3] => dataforinfo4
                    [info4] => dataforinfo4
                    [4] => datafortype
                    [type] => datafortype
                    [5] => dataforformnumber
                    [formnumber] => dataforformnumber

                )

            [1] => Array
                (
                    [0] => dataforinfo1
                    [info1] => dataforinfo1
                    [1] => dataforinfo2
                    [info2] => dataforinfo2
                    [2] => dataforinfo3
                    [info3] => dataforinfo3
                    [3] => dataforinfo4
                    [info4] => dataforinfo4
                    [4] => datafortype
                    [type] => datafortype
                    [5] => dataforformnumber
                    [formnumber] => dataforformnumber
                )
        )

    [ORDERNUMBER] => Array
        (
            [0] => Array
                (
                    [0] => dataforinfo1
                    [info1] => dataforinfo1
                    [1] => dataforinfo2
                    [info2] => dataforinfo2
                    [2] => dataforinfo3
                    [info3] => dataforinfo3
                    [3] => dataforinfo4
                    [info4] => dataforinfo4
                    [4] => datafortype
                    [type] => datafortype
                    [5] => dataforformnumber
                    [formnumber] => dataforformnumber
                )

        )

)
this is what my arrays look like.
i need to run them through a foreach separately
under each ORDERNUMBER i have form data submissions. each ordernumber is unique and can have multiple form data submissions.
i need to be able to assign the data from the form submissions into variables in the foreach.

my foreach should look something like this.

Code: Select all

foreach (each array formnumber data seperatly) {

//set variables
$info1 = dataforinfo1;
$info2 = dataforinfo2;
$info3 = dataforinfo3;
$info4 = dataforinfo4;
$type = datafortype;
$formnumber = dataforformnumber;


//MY CODING WILL BE HERE

}
i need help coding the foreach so that it'll run through the arrays separately
and then i need help assigning the data from the arrays into variables.

thanks a lot!!!
Post Reply