Jump to content

Archived

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

Guest huey4657

My parts are growing out of control?

Recommended Posts

Guest huey4657
Hi all,
Can someone please point out where i am going wrong?
[code]
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
[/code]

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



Share this post


Link to post
Share on other sites
What are you trying to accomplish?  Unless you tell us what the desired output is, we can't help.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest huey4657
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
[color=red]if($RaceEntry_SPPos == $num) // if starting price position equals the loop number
{[/color]
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
[color=red]} // end if[/color]
}  // 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.

Share this post


Link to post
Share on other sites

×

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.