Re: [PHP] $i vs. $r -- coding style ....
Philip Hallstrom wrote: I simplified the code a bit, and I am guessing that it was too much. Below is the complete code that works fine. The weird part is, the part that I have the question on, is if I change $r to $i, it doesn't work anymore. $i doesn't count up as it should and instead gives me some unpredictible results. as it goes down the list sometimes its sequential (1,2,3 but never more than 3), other times its just the number 2 over and over). $r = 1; while ($row = mysql_fetch_array($website_result)) { if (is_int(($r+2)/3)) {echo (\ntr);} echo (\ntd align=\center\ valign=\bottom\); purely aesthetic but maybe your eyes will hurt less if you cut down on the backslashes (and unrequired parentheses) echo \n, 'td align=center valign=bottom'; [echo is special in that it is not a function! rtm for more info ;-)] include($site_path/common/code/directory_format_name.php); I'm going to guess that $site_path/common/code/directory_format_name.php uses $i to do something else on it's own and is therefore messing up your $i. At least that's where I'd start looking. ditto! also I'd suggest that doing this include again and again inside this loop is a bad idea ... maybe try refactoring the code in the include file so that you can use/call it as a function (which has it's own scope and is garanteed _not_ to screw the vars in the calling scope) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] $i vs. $r
Does anyone have a clue why using this code doesn't work: $i = 0; while ($row = mysql_fetch_array($result)) { echo (Blah blah blah); $i++; } but this code does? $r = 0; while ($row = mysql_fetch_array($result)) { echo (Blah blah blah); $r++; } I don't use $i anywhere else on the page. -- Kevin Murphy Webmaster - Information and Marketing Services Western Nevada Community College www.wncc.edu (775) 445-3326 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] $i vs. $r
[snip] Does anyone have a clue why using this code doesn't work: $i = 0; while ($row = mysql_fetch_array($result)) { echo (Blah blah blah); $i++; } but this code does? $r = 0; while ($row = mysql_fetch_array($result)) { echo (Blah blah blah); $r++; } I don't use $i anywhere else on the page. [/snip] While $i is often used as an iterative (hence $i) variable it is not required to be $i. You are echoing $r at the end of the while loop, aren't you? Nothing in the loop requires an $i at this point. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] $i vs. $r
Kevin Murphy wrote: Does anyone have a clue why using this code doesn't work: Please specify what doesn't work means in this case :) $i = 0; while ($row = mysql_fetch_array($result)) { echo (Blah blah blah); $i++; } $r = 0; while ($row = mysql_fetch_array($result)) { echo (Blah blah blah); $r++; } Those two blocks of code are for all intents and purposes identical, and indeed probably end up as exactly the same opcodes. Jasper -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] $i vs. $r
Hello all I simplified the code a bit, and I am guessing that it was too much. Below is the complete code that works fine. The weird part is, the part that I have the question on, is if I change $r to $i, it doesn't work anymore. $i doesn't count up as it should and instead gives me some unpredictible results. as it goes down the list sometimes its sequential (1,2,3 but never more than 3), other times its just the number 2 over and over). $r = 1; while ($row = mysql_fetch_array($website_result)) { if (is_int(($r+2)/3)) { echo (\ntr);} echo (\ntd align=\center\ valign=\bottom\); include($site_path/common/code/directory_format_name.php); // Gets the name Formatter echo (\na href=\/directory/.$row['sup_link']./\img src=\/ images/directory/.$row['sup_picture'].\ border=\0\/a); echo (bra href=\/directory/.$row['sup_link']./\$full_name/ a); echo (\n/td); if (($r = $website_total) AND (is_int(($r+2)/3))) { echo (tdnbsp;/tdtdnbsp;/td/tr); } elseif (($r = $website_total) AND (is_int(($r+1)/3))) { echo (tdnbsp;/td/tr); } elseif (is_int(($r)/3)) echo (\n/tr); $r++; } echo (/table); -- Kevin Murphy Webmaster - Information and Marketing Services Western Nevada Community College www.wncc.edu (775) 445-3326 On Mar 27, 2006, at 3:11 PM, Jasper Bryant-Greene wrote: Kevin Murphy wrote: Does anyone have a clue why using this code doesn't work: Please specify what doesn't work means in this case :) $i = 0; while ($row = mysql_fetch_array($result)) { echo (Blah blah blah); $i++; } $r = 0; while ($row = mysql_fetch_array($result)) { echo (Blah blah blah); $r++; } Those two blocks of code are for all intents and purposes identical, and indeed probably end up as exactly the same opcodes. Jasper -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] $i vs. $r
I simplified the code a bit, and I am guessing that it was too much. Below is the complete code that works fine. The weird part is, the part that I have the question on, is if I change $r to $i, it doesn't work anymore. $i doesn't count up as it should and instead gives me some unpredictible results. as it goes down the list sometimes its sequential (1,2,3 but never more than 3), other times its just the number 2 over and over). $r = 1; while ($row = mysql_fetch_array($website_result)) { if (is_int(($r+2)/3)) { echo (\ntr);} echo (\ntd align=\center\ valign=\bottom\); include($site_path/common/code/directory_format_name.php); I'm going to guess that $site_path/common/code/directory_format_name.php uses $i to do something else on it's own and is therefore messing up your $i. At least that's where I'd start looking. // Gets the name Formatter echo (\na href=\/directory/.$row['sup_link']./\img src=\/images/directory/.$row['sup_picture'].\ border=\0\/a); echo (bra href=\/directory/.$row['sup_link']./\$full_name/a); echo (\n/td); if (($r = $website_total) AND (is_int(($r+2)/3))) { echo (tdnbsp;/tdtdnbsp;/td/tr); } elseif (($r = $website_total) AND (is_int(($r+1)/3))) { echo (tdnbsp;/td/tr); } elseif (is_int(($r)/3)) echo (\n/tr); $r++; } echo (/table); -- Kevin Murphy Webmaster - Information and Marketing Services Western Nevada Community College www.wncc.edu (775) 445-3326 On Mar 27, 2006, at 3:11 PM, Jasper Bryant-Greene wrote: Kevin Murphy wrote: Does anyone have a clue why using this code doesn't work: Please specify what doesn't work means in this case :) $i = 0; while ($row = mysql_fetch_array($result)) { echo (Blah blah blah); $i++; } $r = 0; while ($row = mysql_fetch_array($result)) { echo (Blah blah blah); $r++; } Those two blocks of code are for all intents and purposes identical, and indeed probably end up as exactly the same opcodes. Jasper -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php