Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop logistics 1

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
I tried this to see if it would work first then shout if a problem. How can I do something like this?

for ($i=9;$i<15;$i++)
for ($i=0;$i<9;$i++)
for ($i=15;$i<20;$i++)
for ($i=20;$i<29;$i++)
for ($i=29;$i<38;$i++)
for ($i=38;$i<40;$i++)

} } } } } }

And be able to pass common code within the loop system?
 
ZOR, look at the SWITCH function, it should be about right for this, although the documentation may be a tad flaky.

switch(true){
case ( $i < 1):
// $i-0
// echo or do whatever....
break;

case ($i > 0 AND < 10):
// $i is 1-9
break;

case ($i > 9 AND < 20):
// $i is 10-19
break;

default:
// do something if it doesn't match above
break;
}



______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
sorry, half asleep ... igniore the above, still trying to untangle what you've posted.

What are you trying to achieve?

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Thanks. Proabably easier to put up some code.

for ($i=0;$i<40;$i++)

if ($_SESSION['QTY'][$i]>0) {
//Location
//$LOC=$_SESSION['LOC'][$i];
//Order Number
//$ORDN=$_SESSION['ORDN'][$i];
//Caption
$CAP=$_SESSION['CAPT'][$i];
//Order Date
$ORDD=$_SESSION['Dayte'];
//Group
$GRP=$_SESSION['GRP'][$i];
//Description
$DESC=$_SESSION['DESC'][$i];
//Fuji Part Number
$FPN=$_SESSION['FPNO'][$i];
//Duration
$DUR=$_SESSION['DUR'][$i];
//Unit Price
$UPR=$_SESSION['UPRC'][$i];
//Quantity
$QTY=$_SESSION['QTY'][$i];
//Running Total
$RTL=$_SESSION['OST'][$i];
//Order Total
$OTL=$_SESSION['FINT'];
//VAT
$VAT=$_SESSION['VAT'];

mysql_query ("INSERT INTO orders VALUES ('', NULL, NULL, '$CAP', '$ORDD' , '$GRP' , '$DESC' , '$FPN' ,'$DUR' , '$UPR', '$QTY', '$RTL', '$OTL', '$VAT')");
}

The code above works okay, however it ends up putting rows in the wrong orders. Hence trying to do a concentric loop syatem to deal with the data in batches. Whilst here, is there a way to put the session variables into the insert line? Thanks again
 
Session values in a string isn't to hard:
Code:
mysql_query ("INSERT INTO orders VALUES ('".$_SESSION["VAT"]."')");
You get the idea. Just end quote " dot . session var, dot . quote " continue string.

In what way do you want the order to change for inserting the values? Maybe there is a way to do this without 101 loops.
 
Thanks, that saves a bit. I am now trying to find why the order of records being inserted into the database change. I am inserting records sequentially, but when I look at them in PhpMyAdmin, the rows are in a different order?. I want them to go in as put in. Just with two records, the first row had a primary index of 50 and the second was 49.
Is this a normal thing?. I seem to be chasing around thinking its code thats wrong but it isn't. Can someone confirm this is the case? Thanks
 
Sorry overtired, the database was in decending order. Thanks Aron2, have a star, works a treat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top