Jump to content

Simple loop counter


allinurl

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/112043-simple-loop-counter/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/112043-simple-loop-counter/#findComment-575155
Share on other sites

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.'  ';
    }
}

Link to comment
https://forums.phpfreaks.com/topic/112043-simple-loop-counter/#findComment-575167
Share on other sites

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.'  ';
    }
}

Link to comment
https://forums.phpfreaks.com/topic/112043-simple-loop-counter/#findComment-575182
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.