Jump to content

[SOLVED] URL help


dennismonsewicz

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

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.