Jump to content

Dynamic Variable incrementation loop


l95theses

Recommended Posts

I'm trying to make this code dynamic so that I can decrease it by the number of items in the inventory, this is the static formula to that works, but I don't want to have to add this every time I have another item to check for. Help me to dynamically subtract one from the amount of items. PLEASE!!! thanks...

 

if ( $$itemg == $citem1_array[0] ) {

echo "$citem1_array[1] - $citem1_array[2]";

echo "<br>";

}

if ( $$itemg == $citem2_array[0] ) {

echo "$citem2_array[1] - $citem2_array[2]";

echo "<br>";

}

if ( $$itemg == $citem3_array[0] ) {

echo "$citem3_array[1] - $citem3_array[2]";

echo "<br>";

}

Link to comment
Share on other sites

i dont understand but may be this

 

for ($x=0;$x<=count(fut here the array); $x++)

{

//now put the x on the counter

$array[$x]; and if you want the $xto be 1 or 2 just

$array[$x+1];

}

 

i dont know maybe is that what you mean

Link to comment
Share on other sites

im trying to change the citem in increments untill all of the citems have been checked, so that every item that i have in inventory is gone through, here is the full php doc.

 

<html><body><embed src=retail.swf height=100% width=100% wmode=transparent></body></html>

<?php

$citem2_array[0] = "1";

$citem2_array[1] = "Zephyrhills Spring water";

$citem2_array[2] = "$1.79";

$citem1_array[0] = "2";

$citem1_array[1] = "Kombucha Wonder Drink";

$citem1_array[2] = "$1.59";

$citem3_array[0] = "3";

$citem3_array[1] = "Chocolate Rice Dream Drink";

$citem3_array[2] = "$1.88";

$totalinv = 4;

$totalitems = $_POST['n1'];

$item1 = $_POST['item1'];

$item2 = $_POST['item2'];

$item3 = $_POST['item3'];

$item4 = $_POST['item4'];

$item5 = $_POST['item5'];

$item6 = $_POST['item6'];

$item7 = $_POST['item7'];

$item8 = $_POST['item8'];

$item9 = $_POST['item9'];

$item10 = $_POST['item10'];

$item11 = $_POST['item11'];

$item12 = $_POST['item12'];

$item13 = $_POST['item13'];

$item14 = $_POST['item14'];

$item15 = $_POST['item15'];

$item16 = $_POST['item16'];

$item17 = $_POST['item17'];

$item18 = $_POST['item18'];

$item19 = $_POST['item19'];

$item20 = $_POST['item20'];

$itemnum = 0;

 

while ( $itemnum < 20 ) {

if ( $$itemg == $citem1_array[0] ) {

echo "$citem1_array[1] - $citem1_array[2]";

echo "<br>";

}

if ( $$itemg == $citem2_array[0] ) {

echo "$citem2_array[1] - $citem2_array[2]";

echo "<br>";

}

if ( $$itemg == $citem3_array[0] ) {

echo "$citem3_array[1] - $citem3_array[2]";

echo "<br>";

}

$itemnum = $itemnum + 1;

$itemg = "item" . $itemnum;

}

?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.