Page 2 of 2
Posted: Wed Dec 03, 2003 12:19 pm
by Weirdan
Code: Select all
$tst="3315|Pencils|2|10.24|ON|3320|Textas|2|15.32|ON||||||||";
print_r(getProductArray($tst));
function getProductArray($string){
$res=array();
$str=false;
do{
$res[]=explode("|",$string,6);
$str=end($res);
$string=strlen($str[5])?$str[5]."|":"";
}while($string);
foreach($res as $id=>$row) unset($res[$id][5]);
return $res;
}
Posted: Thu Dec 04, 2003 1:59 am
by UnimatrixZer0
awesome... It works...
But how do I pull individual result out of that array?
Posted: Thu Dec 04, 2003 2:13 am
by UnimatrixZer0
Nevermind, I figured it out... Thanks!
Posted: Thu Dec 04, 2003 5:40 am
by UnimatrixZer0
I'm having trouble figuring out how to get each line out in a variable from that array?
Posted: Thu Dec 04, 2003 5:42 am
by Weirdan
Code: Select all
foreach($result_array as $line){
//.... do something with line
}
Posted: Thu Dec 04, 2003 6:15 am
by UnimatrixZer0
Continuing on from the example you gave above, this is what I have:
foreach($res as $line)
{
$articleNum = $line[1];
$productPackage = $line[2];
$quantity = $line[3];
$price = $line[4];
$gst = $line[5];
I think I may have thrown myself in too deep... lol. Thanks for your help.
Posted: Sat Dec 06, 2003 3:21 am
by UnimatrixZer0
This is the only thing I'm still stuck on now
Posted: Sat Dec 06, 2003 8:07 am
by Weirdan
heh, Uni, I don't understand your requirements. English isn't my native tongue

so could you explain in details what do you need to extract from that array?
Posted: Sat Dec 06, 2003 6:59 pm
by UnimatrixZer0
Code: Select all
<?php
while($i != 9)
{
$articleNum = $results[$i][1];
$productPackage = $results[$i][2];
$quantity = $results[$i][3];
$price = $results[$i][4];
$gst = $results[$i][5];
}
?>
That is continued from your example earlier in this thread... In the code above, I'm trying to extract each of the 5 pieces of information into a variable from the 10 lines that were put into the array.
Thanks for your help once again

Posted: Mon Dec 08, 2003 3:13 am
by Weirdan
UnimatrixZer0 wrote:Code: Select all
<?php
while($i != 9)
{
$articleNum = $results[$i][1];
$productPackage = $results[$i][2];
$quantity = $results[$i][3];
$price = $results[$i][4];
$gst = $results[$i][5];
}
?>
That is continued from your example earlier in this thread... In the code above, I'm trying to extract each of the 5 pieces of information into a variable from the 10 lines that were put into the array.
You're not trying, you're doing it

So what's wrong with the above code? (don't forget to increment $i variable in loop unless you really want infinite loop):
Code: Select all
while($i != 9)
{
$articleNum = $results[$i][1];
$productPackage = $results[$i][2];
$quantity = $results[$i][3];
$price = $results[$i][4];
$gst = $results[$i][5];
//do something
$i++; //increment the $i
}
Posted: Mon Dec 08, 2003 4:53 am
by UnimatrixZer0
The problem is that it returns nothing from the results array.
Posted: Mon Dec 08, 2003 5:10 am
by JayBird
try this just before the while loop then post the results here so we can see what, if anything the results array contains
Code: Select all
echo "<pre>";
print_r($results);
echo "</pre>";
Mark
Posted: Mon Dec 08, 2003 5:20 am
by UnimatrixZer0
Nevermind... Figured out that the $results array was inside a function, therefore not global... And when called on outside that function contained nothing...
Silly me. lol
Posted: Mon Dec 08, 2003 5:25 am
by UnimatrixZer0
It works! Thanks to all who helped with this question!
