plutomed Posted August 15, 2007 Share Posted August 15, 2007 I have this bit of code and it seems to only echo the first one in te array, why? <?php function main_nav() { $main_nav = array( "names" => array("Home", "Pictures", "Templates", "Website Coding"), "pages" => array("index.php", "pictures.php", "templates.php", "website_coding.php") ); $count_main = count($main_nav['names']); $i_main = 0; $i_main2 = 10; $links .= " <a href=\"".$main_nav['pages'][$i_main]."\" class=\"glink\" id=\"g".$i_main2."\">".$main_nav['names'][$i_main]."</a> "; echo $links; while($i_main < $count_main) { $i_main++; $i_main2++; } } ?> Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 15, 2007 Share Posted August 15, 2007 Your loop just increments variables, your echo statement is outside te loop. Try changing this: echo $links; while($i_main < $count_main) { $i_main++; $i_main2++; } to: while($i_main < $count_main) { echo $links; $i_main++; $i_main2++; } Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted August 15, 2007 Share Posted August 15, 2007 because your function echos $links, then loops over some numbers doing nothing: echo $links; // You echo one time, but then.... while($i_main < $count_main) { // Nothing is happening here. $i_main++; $i_main2++; } Quote Link to comment Share on other sites More sharing options...
plutomed Posted August 15, 2007 Author Share Posted August 15, 2007 Thanx I changed it to that and it now works except the increment dosn't seem to be working as it is echoing the same link 4 times ??? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted August 15, 2007 Share Posted August 15, 2007 while($i_main < $count_main) { $links .= " <a href=\"".$main_nav['pages'][$i_main]."\" class=\"glink\" id=\"g".$i_main2."\">".$main_nav['names'][$i_main]."</a> "; $i_main++; $i_main2++; } echo $links; Quote Link to comment Share on other sites More sharing options...
plutomed Posted August 15, 2007 Author Share Posted August 15, 2007 Yes! thanx guys, I know the fist mistake was a stupid one Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.