Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/140570-solved-url-help/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/140570-solved-url-help/#findComment-735614
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/140570-solved-url-help/#findComment-735626
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/140570-solved-url-help/#findComment-735633
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.