Re: $i vs. $r

From: Date: Mon, 27 Mar 2006 23:59:51 +0000
Subject: Re: $i vs. $r
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-232684@lists.php.net to get a copy of this message
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<tr>"); } echo ("\n<td 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 ("\n<a href=\"/directory/".$row['sup_link']."/\"><img src=\"/images/directory/".$row['sup_picture']."\" border=\"0\"></a>"); echo ("<br><a href=\"/directory/".$row['sup_link']."/\">$full_name</a>"); echo ("\n</td>"); if (($r >= "$website_total") AND (is_int(($r+2)/3))) { echo ("<td>&nbsp;</td><td>&nbsp;</td></tr>"); } elseif (($r >= "$website_total") AND (is_int(($r+1)/3))) { echo ("<td>&nbsp;</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


« previous php.general (#232684) next »