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 ("\n");} echo ("\n"); purely aesthetic but maybe your eyes will hurt less if you cut down on the backslashes (and unrequired parentheses) echo "\n", ''; [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
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 ("\n");} echo ("\n"); 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 ("\nsrc=\"/images/directory/".$row['sup_picture']."\" border=\"0\">"); echo ("href=\"/directory/".$row['sup_link']."/\">$full_name"); echo ("\n"); if (($r >= "$website_total") AND (is_int(($r+2)/3))) { echo (" "); } elseif (($r >= "$website_total") AND (is_int(($r+1)/3))) { echo (" "); } elseif (is_int(($r)/3)) echo ("\n"); $r++; } echo (""); -- 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
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 ("\n");} echo ("\n"); include("$site_path/common/code/directory_format_name.php"); // Gets the name Formatter echo ("\nimages/directory/".$row['sup_picture']."\" border=\"0\">"); echo ("$full_namea>"); echo ("\n"); if (($r >= "$website_total") AND (is_int(($r+2)/3))) { echo (" "); } elseif (($r >= "$website_total") AND (is_int(($r+1)/3))) { echo (" "); } elseif (is_int(($r)/3)) echo ("\n"); $r++; } echo (""); -- 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
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
[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
On 3/27/06, Kevin Murphy <[EMAIL PROTECTED]> wrote: > 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 > > > Just a guess, but looks like a scoping issue. That code doesn't show any difference between the two. -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php