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 »

when i print $ordercid this is what i get
Array
(
[2TNVS6] => Array
(
[0] => 828
)

)
Array
(
[2TNVS6] => Array
(
[0] => 828
[1] => 1214
)

)
Array
(
[2TNVS6] => Array
(
[0] => 828
[1] => 1214
[2] => 4690
)

)
Array
(
[2TNVS6] => Array
(
[0] => 828
[1] => 1214
[2] => 4690
)

[W2B368] => Array
(
[0] => 8211
)

)
is that what its supposed to look like?

i thought it shall look like this
Array
(
[2TNVS6] => Array
(
[0] => 828
[1] => 1214
[2] => 4690
)

[W2B368] => Array
(
[0] => 8211
)

)
which it does at the bottom, what is all the stuff before it?
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 it does at the bottom of what? Where are you printing all this? Looks like you're printing from inside a loop while the array is still being built.
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post by donny »

at the bottom of that print i sent.

yes i was lol, i couldn't print it outside of the foreach/while? though it says unassigned
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post by donny »

nevermind i got it . its beautiful!
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post by donny »

now i need some help pulling the form info from the database. i am using the script that i used in the beginning, i need help adjusting it to call the new array out.

Code: Select all

<?php
include 'dblogin.php';
$select_list = $_POST['selected'];
foreach ($select_list as $key => $value) {
        $select_list[$key] = "'" . $value . "'";
}
$list = implode(', ', $select_list);

$query = "SELECT `ordernumber`, `formnumber` FROM `rawdata` WHERE `ordernumber` IN ($list)";
$result = mysql_query($query) or die(mysql_error());

$ordercid = array();
while ($row = mysql_fetch_array($result)) {
        $ordercid[$row['ordernumber']][] = $row['formnumber'];
}


foreach ($ordercid as $ordernumber => $CID) {
$query2 = "SELECT * FROM `rawdata` WHERE `ordernumber` = '$ordernumber' AND `formnumber` = '$CID'"; 
	 
$result2 = mysql_query($query2) or die(mysql_error());


while($row2 = mysql_fetch_array($result2)){
$clientarray = array(	"ordernumber" => $row['ordernumber'], 
						"formnumber" => $row['formnumber'], 
						"info1" => $row['info1'],
						"info2" => $row['info2'],
						"info3" => $row['info3'],
						"info4" => $row['info4'],
						"type" => $row['type']);
										}

}

echo "Check box test<pre>" ;
print_r($clientarray); 
echo "</pre>"
?>
thanks so much!
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 »

Just FYI, if you ever find yourself running a query inside a loop. Stop. Thinking about the problem and about what you really need, because there's almost always a better way. In this case, I don't see a need for the second query at all. You're querying the same table, just grab all the data on the first pass.
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post by donny »

i can't get it on the first pass because its 2 different tables. if i get everything from raw data i will come up with multiple results since theres more than 1 of the same ordernumber on the raw data list. i have a orders table that has all the order numbers one time in them. thats the table i am using for the orders list because i have other information on that table like paid and status and stuff.
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post by donny »

actually never mind your right. very tired. been at this since last night!!!

how can i get all rows from the table into the 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 »

Code: Select all

$query = "SELECT `ordernumber`, `form number`, `info1`, `info2`, `info3`, `info4`, `type` FROM `rawdata` WHERE `ordernumber` IN ($list)";
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post by donny »

actually i don't think i can do it this way...

i need to have all data separate for each formnumber. it would have to be a 3 dimensional array i guess

Array
(
[2TNVS6] => Array
(
[8028] => Array
(
[info1] => data
[info2] => data
[info3] => data
[info4] => data
(
[2031] => Array
(
[info1] => data
[info2] => data
[info3] => data
[info4] => data
(
[9450] => Array
(
[info1] => data
[info2] => data
[info3] => data
[info4] => data
(
)

[W2B368] => Array
(
[1203] => Array
(
[info1] => data
[info2] => data
[info3] => data
[info4] => data
(
[9984] => Array
(
[info1] => data
[info2] => data
[info3] => data
[info4] => data
(
)

[C0XM4B] => Array
(
[2393] => Array
(
[info1] => data
[info2] => data
[info3] => data
[info4] => data
(
)

)


ORDERNUMBER
FORMNUMBER
FORMDATA
FORMNUMBER
FORMDATA
ORDERNUMBER
FORMNUMBER
FORMDATA
etc

is this possible?
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 »

Why a three dimensional array? Why couldn't you just operate on the rows directly? Barring that, why not just expand the current 2d array?

Which is to say

Code: Select all

$ordercid = array();
while ($row = mysql_fetch_array($result)) {
        $ordercid[$row['ordernumber']][] = $row;
}
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post by donny »

i need to have all form data separately...

in my table i have

ordernumber formnumber data1 data2 data3

the same ordernumber can have multiple formnumbers because they submitted multiple forms for the same order

i need to have all information separate to pass through the foreach script seperartly.
Last edited by donny on Thu Sep 04, 2014 7:14 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 »

That in no way answers my second question.
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post by donny »

why can't i operate on the rows directly? i don't understand
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: PHP Batch Process? Is this Possible?

Post by donny »

ah i see. that will work
Post Reply