allinurl Posted June 26, 2008 Share Posted June 26, 2008 Hello, What I'm trying to do is basically the same thing is doing right now, with the same formula, with the exception of, when I click 1 the <a href> shouldnt be "index.php?num=-10&var=1" it should be just index.php $num = ((int) $_GET['num']); for ($i = 1; $i < 12; $i++) { $val = ($i - 2 )* 10; if ($val < -10) { print '<strong><a href="index.php">'.$i.'</a></strong> '; } else if ($val != $num) { print '<strong><a href="index.php?num='.$val.'&var=1">'.$i.'</a></strong> '; } else { print $i.' '; } } Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/112043-simple-loop-counter/ Share on other sites More sharing options...
xyn Posted June 26, 2008 Share Posted June 26, 2008 I'm confused about what your trying to archieve, coudl re-explain? Quote Link to comment https://forums.phpfreaks.com/topic/112043-simple-loop-counter/#findComment-575149 Share on other sites More sharing options...
allinurl Posted June 26, 2008 Author Share Posted June 26, 2008 thanks for your reply, well basically what I'm trying to do is a counter that for instance when I click in number 2 the $num value should start at 0, if I click on 3 the $num value should be 10 and so on, but when I click on 1 it should be just the url with out any param. In addition it doesn't make the current number a link. Quote Link to comment https://forums.phpfreaks.com/topic/112043-simple-loop-counter/#findComment-575155 Share on other sites More sharing options...
.josh Posted June 26, 2008 Share Posted June 26, 2008 well, you could add a condition to check if $i == 1 and if so, build link without the added stuff, or you could just do a plain echo of it before the loop and start your loop at 2 instead of 1. Quote Link to comment https://forums.phpfreaks.com/topic/112043-simple-loop-counter/#findComment-575157 Share on other sites More sharing options...
allinurl Posted June 26, 2008 Author Share Posted June 26, 2008 if I add a condition to check if $i == 1 then when I click 1 it keeps been a link $num = ((int) $_GET['num']); for ($i = 1; $i < 12; $i++) { $val = ($i - 2 )* 10; if ($i == 1) { print '<strong><a href="index.php">'.$i.'</a></strong> '; } else if ($val != $num) { print '<strong><a href="index.php?num='.$val.'&var=1">'.$i.'</a></strong> '; } else { print $i.' '; } } Quote Link to comment https://forums.phpfreaks.com/topic/112043-simple-loop-counter/#findComment-575167 Share on other sites More sharing options...
xyn Posted June 26, 2008 Share Posted June 26, 2008 if ($i <= 1) { #code } Quote Link to comment https://forums.phpfreaks.com/topic/112043-simple-loop-counter/#findComment-575174 Share on other sites More sharing options...
.josh Posted June 26, 2008 Share Posted June 26, 2008 well I think this is what you are trying to do... $num = ((int) $_GET['num']); for ($i = 1; $i < 12; $i++) { $val = ($i - 2 )* 10; if ($val != $num) { if ($i == 1) { print '<strong><a href="index.php">'.$i.'</a></strong> '; } else { print '<strong><a href="index.php?num='.$val.'&var=1">'.$i.'</a></strong> '; } } else { print $i.' '; } } Quote Link to comment https://forums.phpfreaks.com/topic/112043-simple-loop-counter/#findComment-575182 Share on other sites More sharing options...
allinurl Posted June 26, 2008 Author Share Posted June 26, 2008 thanks both, but when I click on 1 still makes me look like if I'm in number 2, and 1 is still a link. The idea is basically the same functionality as now, but when I click on each number I dont wanna make that current number a link Quote Link to comment https://forums.phpfreaks.com/topic/112043-simple-loop-counter/#findComment-575184 Share on other sites More sharing options...
.josh Posted June 26, 2008 Share Posted June 26, 2008 well i have no idea what the point of $val is supposed to be but if you want the "current" one not to be a link then you need a condition to see if ($i == $num) Quote Link to comment https://forums.phpfreaks.com/topic/112043-simple-loop-counter/#findComment-575189 Share on other sites More sharing options...
allinurl Posted June 26, 2008 Author Share Posted June 26, 2008 where specifically I should have the condition? Quote Link to comment https://forums.phpfreaks.com/topic/112043-simple-loop-counter/#findComment-575209 Share on other sites More sharing options...
.josh Posted June 26, 2008 Share Posted June 26, 2008 if you have a bunch of numbers you want to loop through, and one of those numbers you want to do something special with, where do you think the condition should be? Quote Link to comment https://forums.phpfreaks.com/topic/112043-simple-loop-counter/#findComment-575226 Share on other sites More sharing options...
allinurl Posted June 26, 2008 Author Share Posted June 26, 2008 beginning, but still don't get it. Quote Link to comment https://forums.phpfreaks.com/topic/112043-simple-loop-counter/#findComment-575240 Share on other sites More sharing options...
allinurl Posted June 26, 2008 Author Share Posted June 26, 2008 got it thanks Quote Link to comment https://forums.phpfreaks.com/topic/112043-simple-loop-counter/#findComment-575249 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.