Jump to content


My parts are growing out of control?


  • Please log in to reply
3 replies to this topic

#1 Guest_huey4657_*

Guest_huey4657_*
  • Guests

Posted 11 August 2006 - 03:06 PM

Hi all,
Can someone please point out where i am going wrong?
while($SqlRow_GetStats = mysql_fetch_array($SqlRes_GetStats)) // if there is a row do this (300000+ times max)
{
extract($SqlRow_GetStats); // extract row into variables named after field name
$RaceIDs[$cnt] = $Race_ID;  // create array of IDs
$FPoss[$cnt] = $RaceEntry_FPos;  // create array of race finish position
$SPPoss[$cnt] = $RaceEntry_SPPos;  // create array of starting price position

for($num = 1; $num <= $SqlNum_GetSPos; $num++) // 18 times
{
$Row18[$num] = $num; // does the same as group by and sort
if($RaceEntry_FPos == "1")  // field extracted equals 1
{
$Win[$num]++; // increment array position by 1
}
elseif ($RaceEntry_FPos >= "2" AND $RaceEntry_FPos <= "3")  // field extracted is either 2 or 3
{
$Place[$num]++;  // increment array position by 1
}
else 
{
$Lost[$num]++;  // increment array position by 1
}  // end if
}  // end for

after printing contents of arrays they equal

$Win[1] = 36137 $Place[1] = 71719 $Lost[1] = 241535
$Win[2] = 36137 $Place[2] = 71719 $Lost[2] = 241535
$Win[3] = 36137 $Place[3] = 71719 $Lost[3] = 241535
etc...

thanks for your help





#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 11 August 2006 - 11:16 PM

What are you trying to accomplish?  Unless you tell us what the desired output is, we can't help.

#3 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 12 August 2006 - 12:01 AM

Doesn't look like there's anything actually wrong with that code. Your FOR loop will do exactly the same each tiime as the IF statement tests the same variable each time, so of course you will get all the rows the same.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#4 Guest_huey4657_*

Guest_huey4657_*
  • Guests

Posted 12 August 2006 - 10:19 AM

Yes, sorry all
the problem was me, i had been coding all day and missed a conditional statement.

This worked...

while($SqlRow_GetStats = mysql_fetch_array($SqlRes_GetStats)) // if there is a row do this (300000+ times max)
{
extract($SqlRow_GetStats); // extract row into variables named after field name
$RaceIDs[$cnt] = $Race_ID;  // create array of IDs
$FPoss[$cnt] = $RaceEntry_FPos;  // create array of race finish position
$SPPoss[$cnt] = $RaceEntry_SPPos;  // create array of starting price position

for($num = 1; $num <= $SqlNum_GetSPos; $num++) // 18 times
{
$Row18[$num] = $num; // does the same as group by and sort
if($RaceEntry_SPPos == $num) // if starting price position equals the loop number
{

if($RaceEntry_FPos == "1")  // field extracted equals 1
{
$Win[$num]++; // increment array position by 1
}
elseif ($RaceEntry_FPos >= "2" AND $RaceEntry_FPos <= "3")  // field extracted is either 2 or 3
{
$Place[$num]++;  // increment array position by 1
}
else
{
$Lost[$num]++;  // increment array position by 1
}  // end if
} // end if
}  // end for


now i get the correct results below:

$Row18 = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 // saves me doing a group by and sort function

$Win[1] = 13713 $Place[1] = 12632 $Lost[1] = 13254 // outputs all race entries that are in starting position 1 and and have either won, placed or lost.
$Win[2] = 8057 $Place[2] = 14876 $Lost[2] = 17930 // same as above but for starting position 2
$Win[3] = 5289 $Place[3] = 13537 $Lost[3] = 22728 // starting position 3
etc... till 18.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users