Jump to content

Arrays and Loops


kitchen

Recommended Posts

[code] function listQueue($category)
{
global $total;
global $arr_id;
global $arr_am;

$query = "SELECT * FROM market WHERE cat = '$category'";
$result = mysql_query($query);

while($item = mysql_fetch_array($result))
{
$amount = $_POST[$item['id']];

if(is_numeric($amount))
{
if($amount > 0)
{
$itotal = $item['cost'] * $amount;
$total = $total + $itotal;
$fitotal = number_format($item['cost'] * $amount);
$fcost  = number_format($item['cost']);
$famount = number_format($amount);
$arr_id[$i] = "$item[id]";
$arr_am[$i] = "$amount";
$i++;
}
}
}
}

#Lots of code was here, I removed it all it did was teh call fucntion and thats not the problem :-P

foreach($arr_am as $aa)
{
foreach($arr_id as $ai)
{
$x = 0;

while($aa > $x)
{
echo $ai;
$x++;
}
}
} [/code]

Ok so now my problem is this, I have lots of forms where the amounts are being entered. Lets use 2 of them as an example.

I enter the value of 1 in to form 1
I enter the value of 2 in to form 2

I want the output to be: 122
The current output is:121122

Hope that makes sense if not, please ask for what more information you need.
Link to comment
https://forums.phpfreaks.com/topic/34713-arrays-and-loops/
Share on other sites

[quote author=boo_lolly link=topic=122957.msg507920#msg507920 date=1169140355]
i [i]think[/i] he means he wants the output 122 to mean that the first value was 1, the second value was 2, and there were 2 forms total where data was entered... that's as far as i got.
[/quote]

thats percisely what i want to do!
Link to comment
https://forums.phpfreaks.com/topic/34713-arrays-and-loops/#findComment-164115
Share on other sites

Almost like that. I have various forms, each labeled by id's taken from a mysql database, i want the output to equal the id number, repeated X amount of times (x = what number u entered in the form)

so lemme say the example a little clearer :P

user enters the value 1 into the form labled 4, the user enters the value 2 label 5 - the output is 454455, but I want the output to be 455

Hope you can make sense out of that lol
Link to comment
https://forums.phpfreaks.com/topic/34713-arrays-and-loops/#findComment-164714
Share on other sites

[quote author=sasa link=topic=122957.msg509030#msg509030 date=1169267307]
try[code]foreach($arr_am as $ai => $aa)
{
// foreach($arr_id as $ai)
// {
$x = 0;

while($aa > $x)
{
echo $arr_id[$ai];
$x++;
}
// }
} [/code]
[/quote]

Thanks dude! That works perfectly!

EDIT: I can't find the topic solved link =/
Link to comment
https://forums.phpfreaks.com/topic/34713-arrays-and-loops/#findComment-164937
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.