dennismonsewicz Posted January 12, 2009 Share Posted January 12, 2009 I have the following code: $i = 5; while($i <= 50) { echo '<a style="display: inline block; padding: 5px;" href="' . $_SERVER['REQUEST_URI'] . '&limit=' . $i . '">' . $i . '</a>'; $i += 5; } ' When a user clicks on a link the first time the URL is correct but if a user clicks on a second link the url appends the &limit=$i; IE: limit=5&limit=10&limit=15; i need it to replace the limit= everytime a link is clicked. Help please? Quote Link to comment https://forums.phpfreaks.com/topic/140570-solved-url-help/ Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 What do you mean replace the limit everytime, do you mean restart the count or change the current url? if the latter then do echo '<a style="display: inline block; padding: 5px;" href="http://' . $_SERVER['HTTP_HOST'].'/?limit=' . $i . '">' . $i . '</a>'; Without more info about the url, i can't help much more Quote Link to comment https://forums.phpfreaks.com/topic/140570-solved-url-help/#findComment-735614 Share on other sites More sharing options...
dennismonsewicz Posted January 12, 2009 Author Share Posted January 12, 2009 i am actually doing this in a different manner... LOL updated code: Results to display: <select name="limit"> <?php $i = 5; while($i <= 50) { if($i == $limit) { $s = "SELECTED"; } echo '<option value="' . $i . '" ' . $s . '>' . $i . '</option>'; $i += 5; } ?> </select> <input type="submit" name="limit_submit" /> # of Results currently displaying: <?php echo $limit; ?> I have a new problem though. my if statement is not working... $limit is being passed via a function. how would i check to see if $limit = $i and if so then place the s var? $limit is being passed via a function Quote Link to comment https://forums.phpfreaks.com/topic/140570-solved-url-help/#findComment-735626 Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 If i understand correct, then like <?php $i = 5; while($i <= 50) { if($i == $limit) $s = "SELECTED"; else $s = ""; echo '<option value="' . $i . '" ' . $s . '>' . $i . '</option>'; $i += 5; } ?> Edit ignore that is it practically the same as you have, what function is passing limit? and try echoing limit within the loop to see if it is correct Quote Link to comment https://forums.phpfreaks.com/topic/140570-solved-url-help/#findComment-735633 Share on other sites More sharing options...
dennismonsewicz Posted January 12, 2009 Author Share Posted January 12, 2009 sweet it works! I was doing an if statement without the else and it was defaulting to selecting the last number in the incremented list (50)... thanks again bud! Quote Link to comment https://forums.phpfreaks.com/topic/140570-solved-url-help/#findComment-735636 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.