Page 5 of 7

Re: PHP Batch Process? Is this Possible?

Posted: Thu Sep 04, 2014 10:30 am
by Celauran
You have the same array key twice. That's not going to work. Using a multidimensional array should solve that, though.

Code: Select all

$selected = [
	["PH62W8" => "8482"],
	["PH62W8" => "7437"],
	["FRF856" => "5207"],
	["62R9PK" => "4696"],
];
Also, unrelated but something to consider, how is this

Code: Select all

$clientarray = array(   "ordernumber" => $row['ordernumber'], 
                "formnumber" => $row['formnumber'], 
                "info1" => $row['info1'],
                "info2" => $row['info2'],
                "info3" => $row['info3'],
                "info4" => $row['info4'],
                "type" => $row['type']);
different from this?

Code: Select all

$clientarray = $row;

Re: PHP Batch Process? Is this Possible?

Posted: Thu Sep 04, 2014 10:32 am
by Celauran
Alternately,

Code: Select all

$selected = [
	"PH62W8" => ["8482", "7437"],
	"FRF856" => ["5207"],
	"62R9PK" => ["4696"],
];

Re: PHP Batch Process? Is this Possible?

Posted: Thu Sep 04, 2014 10:44 am
by donny
lol @ array () being different than = $row .. i didnt know about that lol, it does add everything twice into the array but it really doesn't matter i guess.makes it easier i guess with the numbers instead of writing out all column names pretty cool.

so if i change the key to a unique number it would work?

sorry i am learning trying to do as much as i can on my own

Re: PHP Batch Process? Is this Possible?

Posted: Thu Sep 04, 2014 10:50 am
by donny
would you mind please helping me set up a multidimensional array please?

coming into the page with an array that includes ordernumber and form number like this

Code: Select all

$selected = array(  "PH62W8" => "8482",
					"PH62W8" => "7437",
					"FRF856" => "5207",
					"62R9PK" => "4696"
				 );
ordernumber => formnumber

then ill be getting the info out of the database and inserting all my results into a multidimensional array setup something like this

Code: Select all

$processthese = array( 
						array($row),
						array($row),
						array($row) 
    		         ); 
$row would be replaced with the table information.

remember i am using outdated PHP ! lol php5 arrays won't work for me!
thanks a lot

Re: PHP Batch Process? Is this Possible?

Posted: Thu Sep 04, 2014 11:11 am
by Celauran
Update your PHP. Short array syntax has been available since 5.4, which is the oldest version currently supported. There's really no reason to use an outdated version. Newer versions offer security fixes and significant performance gains. 5.3 to 5.4 is like night and day.

Re: PHP Batch Process? Is this Possible?

Posted: Thu Sep 04, 2014 11:13 am
by Celauran
donny wrote:coming into the page with an array that includes ordernumber and form number like this

Code: Select all

$selected = array(  "PH62W8" => "8482",
					"PH62W8" => "7437",
					"FRF856" => "5207",
					"62R9PK" => "4696"
				 );
That's a bad assumption. You're only coming into the page with the last three items since the second overwrites the first because of the duplicate key. Where are these values coming from? That's where you need to implement the fix. Show me how the array is initially being created and I can help you iron that out.

Re: PHP Batch Process? Is this Possible?

Posted: Thu Sep 04, 2014 11:15 am
by donny
ok yeah that was just an example. i thought you had said multi dimensional arrays would sort that out. i am working on the select page now though

Re: PHP Batch Process? Is this Possible?

Posted: Thu Sep 04, 2014 11:44 am
by donny

Code: Select all

<form action="select.php" method="post">
<table class="tg">
  <tr>
    <th class="tg-031e">SELECT</th>
    <th class="tg-031e">ORDER NUMBER</th>
  </tr>
<?php
include 'dblogin.php';
$query = "SELECT * FROM `orders`"; 
	 
$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){
?>
  <tr>
    <td class="tg-031e"><input type="checkbox" name="selected[]" value="<?php echo$row['ordernumber'];?>"></td>
    <td class="tg-031e"><?php echo $row['ordernumber']; ?></td>
  </tr>
<?
}
?>
<input type="submit" value="Select">
</form>
</table>
this will put all order numbers into an array on the next page.
from that array i will need to go into the database and get formnumbers for each ordernumber to put into an array.

this is where i am going to run into problems with having duplicate keys, but i was thinking if i made formnumbers the key instead i shouldn't have that problem. but there can be a very rare case where i can have duplicate formnumbers since it is not a unique number, my order numbers are unique but my formnumbers aren't. i figured i only needed one of them to be unique because every time id hit the database for them i would include both of them in the query.

Re: PHP Batch Process? Is this Possible?

Posted: Thu Sep 04, 2014 11:51 am
by Celauran
I don't see a problem yet. Submitting this form will give you an array of order numbers. Once the form has been submitted, you can grab the relevant form numbers and build your array there. Explode the submitted array into a comma-separated list, query order number and form number where order number IN that list and then build up the array from the results.

Something like this.

Code: Select all

$list = implode(', ', $_POST['submitted']);
$query = "SELECT ordernumber, formnumber FROM orders WHERE ordernumber IN ($list)";

Re: PHP Batch Process? Is this Possible?

Posted: Thu Sep 04, 2014 11:59 am
by donny
Warning: explode() expects parameter 2 to be string, array given in select.php on line 2

Re: PHP Batch Process? Is this Possible?

Posted: Thu Sep 04, 2014 12:04 pm
by Celauran
That should have read implode. My bad. I fixed the example.

Re: PHP Batch Process? Is this Possible?

Posted: Thu Sep 04, 2014 12:23 pm
by donny
this is what i am getting
Unknown column '2TNVS6' in 'where clause'

i truncated the tables and only have 2 orders in there the first order has 3 forms under it.

this is my SQL

Code: Select all

$query = "SELECT ordernumber, clientid FROM rawdata WHERE ordernumber IN ($list)";
i changed it to rawdata because thats where the form submissions are stored. i used order in the page to select which order numbers i want to chose to process.

Re: PHP Batch Process? Is this Possible?

Posted: Thu Sep 04, 2014 12:35 pm
by Celauran
Because they aren't numeric keys, you'll want to wrap them in quotes.

Re: PHP Batch Process? Is this Possible?

Posted: Thu Sep 04, 2014 12:54 pm
by donny
ok now i am stuck. I'm trying to make the array with the ordernumbers and formnumbers that need to be processed.

Code: Select all

<?php
$list = implode(', ', $_POST['selected']);

	
include 'dblogin.php';

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


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

}
?>

Re: PHP Batch Process? Is this Possible?

Posted: Thu Sep 04, 2014 1:22 pm
by Celauran
You really should stop with the mysql_ functions.

That said, this should do the trick

Code: Select all

$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'];
}