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
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Wed Dec 03, 2003 12:19 pm
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;
}
UnimatrixZer0
Forum Newbie
Posts: 17 Joined: Wed Dec 03, 2003 5:06 am
Post
by UnimatrixZer0 » Thu Dec 04, 2003 1:59 am
awesome... It works...
But how do I pull individual result out of that array?
UnimatrixZer0
Forum Newbie
Posts: 17 Joined: Wed Dec 03, 2003 5:06 am
Post
by UnimatrixZer0 » Thu Dec 04, 2003 5:40 am
I'm having trouble figuring out how to get each line out in a variable from that array?
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Thu Dec 04, 2003 5:42 am
Code: Select all
foreach($result_array as $line){
//.... do something with line
}
UnimatrixZer0
Forum Newbie
Posts: 17 Joined: Wed Dec 03, 2003 5:06 am
Post
by UnimatrixZer0 » Thu Dec 04, 2003 6:15 am
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.
UnimatrixZer0
Forum Newbie
Posts: 17 Joined: Wed Dec 03, 2003 5:06 am
Post
by UnimatrixZer0 » Sat Dec 06, 2003 3:21 am
This is the only thing I'm still stuck on now
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Sat Dec 06, 2003 8:07 am
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?
UnimatrixZer0
Forum Newbie
Posts: 17 Joined: Wed Dec 03, 2003 5:06 am
Post
by UnimatrixZer0 » Sat Dec 06, 2003 6:59 pm
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
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Mon Dec 08, 2003 3:13 am
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
}
UnimatrixZer0
Forum Newbie
Posts: 17 Joined: Wed Dec 03, 2003 5:06 am
Post
by UnimatrixZer0 » Mon Dec 08, 2003 4:53 am
The problem is that it returns nothing from the results array.
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Mon Dec 08, 2003 5:10 am
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
UnimatrixZer0
Forum Newbie
Posts: 17 Joined: Wed Dec 03, 2003 5:06 am
Post
by UnimatrixZer0 » Mon Dec 08, 2003 5:20 am
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
UnimatrixZer0
Forum Newbie
Posts: 17 Joined: Wed Dec 03, 2003 5:06 am
Post
by UnimatrixZer0 » Mon Dec 08, 2003 5:25 am
It works! Thanks to all who helped with this question!