Is it possible to have stuff echo'd based on the address in the address bar of your browser ?

So like...

if address in the address bar = index.php?page=21

then echo the below

echo "Page " . number_format($page) . " of " . number_format($totalpages) . "<br />";
		   
	  $starting_user = $i = ($page - 1) * $h + 1;
	  
	  echo "Results: " . number_format($starting_user) . " to " . number_format(min($starting_user+$h-1, $num)) . "<br />";

      if ($page > 1) {
		 echo '&nbsp;<a href="index.php?page=21" title="First Page">First</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		 echo '<a href="index.php?page=21;p='.$prevpage.'" title="Previous Page">Previous</a>';
      }
      else {
         echo '&nbsp;First&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		 echo 'Previous';
      }

		 echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';

      if ($page < $totalpages) {
         echo '<a href="index.php?page=21;p='.$nextpage.'" title="Next Page">Next</a> ';
         echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="index.php?page=21;p='.$totalpages.'" title="Last Page">Last</a>&nbsp;';
      }
      
      else {
		 echo 'Next';
		 echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Last&nbsp;';
      }

if address in the address bar = index.php?page=21;l='.$get_letters.'

then echo the below

echo "Page " . number_format($page) . " of " . number_format($totalpages) . "<br />";
		   
	  $starting_user = $i = ($page - 1) * $h + 1;
	  
	  echo "Results: " . number_format($starting_user) . " to " . number_format(min($starting_user+$h-1, $num)) . "<br />";

      if ($page > 1) {
		 echo '&nbsp;<a href="index.php?page=21;l='.$get_letters.'" title="First Page">First</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		 echo '<a href="index.php?page=21;l='.$get_letters.';p='.$prevpage.'" title="Previous Page">Previous</a>';
      }
      else {
         echo '&nbsp;First&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		 echo 'Previous';
      }

		 echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';

      if ($page < $totalpages) {
         echo '<a href="index.php?page=21;l='.$get_letters.';p='.$nextpage.'" title="Next Page">Next</a> ';
         echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="index.php?page=21;l='.$get_letters.';p='.$totalpages.'" title="Last Page">Last</a>&nbsp;';
      }
      
      else {
		 echo 'Next';
		 echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Last&nbsp;';
      }

if address in the address bar = index.php?page=21;n='.$get_numbers.'

then echo the below

echo "Page " . number_format($page) . " of " . number_format($totalpages) . "<br />";
		   
	  $starting_user = $i = ($page - 1) * $h + 1;
	  
	  echo "Results: " . number_format($starting_user) . " to " . number_format(min($starting_user+$h-1, $num)) . "<br />";

      if ($page > 1) {
		 echo '&nbsp;<a href="index.php?page=21;n='.$get_numbers.'" title="First Page">First</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		 echo '<a href="index.php?page=21;n='.$get_numbers.';p='.$prevpage.'" title="Previous Page">Previous</a>';
      }
      else {
         echo '&nbsp;First&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		 echo 'Previous';
      }

		 echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';

      if ($page < $totalpages) {
         echo '<a href="index.php?page=21;n='.$get_numbers.';p='.$nextpage.'" title="Next Page">Next</a> ';
         echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="index.php?page=21;n='.$get_numbers.';p='.$totalpages.'" title="Last Page">Last</a>&nbsp;';
      }
      
      else {
		 echo 'Next';
		 echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Last&nbsp;';
      }

I'm not sure if you know this already but just in case you dont.

To get the variable in the address bar into the page i.e., page use $page=$_GET['page'] This for your first example would return $page=21. Based on the variables you can echo what you need.

Similarly for the rest.

I'm not sure if you know this already but just in case you dont.

To get the variable in the address bar into the page i.e., page use

$page=$_GET['page']

This for your first example would return $page=21. Based on the variables you can echo what you need.

Similarly for the rest.

I tried something like that using the below but because of the way the URL's are it would only let me use 21 and nothing else...

  $pg = (int) $_GET[ 'page' ];
  if( 21 === $pg ) {echo 'Test...';}

Try this

$pg = $_GET['page'];
if($pg==21) {echo 'Test...';}

You should then be able to elseif for the other values.

$pg = $_GET['page'];
if($pg==21) {
   echo 'Test...';
} else if ($pg==22) {
   echo 'test2'; 
}

Try this

$pg = $_GET['page'];
if($pg==21) {echo 'Test...';}

You should then be able to elseif for the other values.

$pg = $_GET['page'];
if($pg==21) {
   echo 'Test...';
} else if ($pg==22) {
   echo 'test2'; 
}

Because of the special characters in my link it doesnt appear to want to work, thats what I guess I was trying t osay before.

$pg = $_GET;
if($pg==21) { echo 'Regular...';}
else if ($pg==21;n='.$get_numbers.') { echo 'Numbers...'; }
else if ($pg==21;l='.$get_letters.') { echo 'Letters...'; }

Gives me this: syntax error, unexpected ';'

Please encapsulate your string literals in quotes. else if ($pg=="21;n='.$get_numbers.'") { echo 'Numbers...'; } The direct entry for the 21 is because of the integer. You need to encase the string in quotes to do the check.

In your code $get_numbers and $get_letters are variables.
In the urls in the link you are building you are using the value of those variables in the url.

So, <a href="index.php?page=21;l='.$get_letters.'" would become <a href="index.php?page=21;l=1" in your html. If the value of $get_letters was 1. This would mean the value of $_GET would be '21;l=1' sans the quotes.

In your urls you are also concatenating the variables together with a semi-colon. If these are two different values they need to be passed with an ampersand. <a href="index.php?page=21&l='.$get_letters.'" In your code you can then test for these as separate values. $_GET and $_GET.

$page = (int) $_GET['page'];
$letter = $_GET['l'];
$numbers = $_GET['n'];

Please encapsulate your string literals in quotes. else if ($pg=="21;n='.$get_numbers.'") { echo 'Numbers...'; } The direct entry for the 21 is because of the integer. You need to encase the string in quotes to do the check.

That did the trick, I guess I;mn so eager to finish this I just didn;t even think of that when I should have. So thx...

However, we're now left wiht a bit of an issue...

http://www.eojmarket.com/index.php?page=21

If You click between Show All, Any of the numbers and then any of the letters you will notice that Regular always shows.

When clicking around 0-9 Numbers... should show and when clicking arund A-Z Letters... should always show but they dont, Regular always shows and I think it's because of the 21.

I'm guessing thats all the code is looking at while everything else like the below is being ignored.

;n='.$get_numbers.'
;n='.$get_letters.'

Obviously Regular, Numbers & Letters isnt my ultimate goal with this code but it gets the testing done.

This is whats being used...

$pg = $_GET;
if($pg==21) { echo 'Regular...';}
else if ($pg=="21;n='.$get_numbers.'") { echo 'Numbers...'; }
else if ($pg=="21;l='.$get_letters.'") { echo 'Letters...'; }

I guess I wasnt specific enough when I made the post but I need data to show based on the exact link being displayed in the address bar.

In your code $get_numbers and $get_letters are variables.
In the urls in the link you are building you are using the value of those variables in the url.

So, <a href="index.php?page=21;l='.$get_letters.'" would become <a href="index.php?page=21;l=1" in your html. If the value of $get_letters was 1. This would mean the value of $_GET would be '21;l=1' sans the quotes.

In your urls you are also concatenating the variables together with a semi-colon. If these are two different values they need to be passed with an ampersand. <a href="index.php?page=21&l='.$get_letters.'" In your code you can then test for these as separate values. $_GET and $_GET.

$page = (int) $_GET['page'];
$letter = $_GET['l'];
$numbers = $_GET['n'];

All the get stuff for letters and numbers has already been worked out...

PHP is a loosely typed language.
$pg is always a string result from the url e.g. '21', '21;n=0', '21;l=0'

When you do a comparison against an integer value if($pg == 21) { echo 'Regular...';} $pg is cast to an integer value. So var_dump( (int) '21;n=0' ); will yield int 21.

Since you're doing a string comparison across the whole thing, instead of == 21 it should be == '21' OR you should split those up into individual variables and test the parameters individually like I was trying to suggest before...

PHP is a loosely typed language.
$pg is always a string result from the url e.g. '21', '21;n=0', '21;l=0'

When you do a comparison against an integer value if($pg == 21) { echo 'Regular...';} $pg is cast to an integer value. So var_dump( (int) '21;n=0' ); will yield int 21.

Since you're doing a string comparison across the whole thing, instead of == 21 it should be == '21' OR you should split those up into individual variables and test the parameters individually like I was trying to suggest before...

Well, I know little to nothing about PHP, especially when it comes to stuff like this so in reality I have no idea what your talking about. Also, all of this code is work someone did for me a long time ago that I sort of added to in times past.

The solution was provided in my previous post

instead of == 21 it should be == '21'

There is no value to me just giving you the solution and you just copying and pasting it into your code. By providing you the information I did, you can attempt to learn why you're having a problem and how to address it in the future.

You're still going to have a problems with the additional code you posted too:

else if ($pg=="21;n='.$get_numbers.'") { echo 'Numbers...'; }
else if ($pg=="21;l='.$get_letters.'") { echo 'Letters...'; }

$pg=="21;n='.$get_numbers.'" and pg=="21;l='.$get_letters.'" are not going to match "21;n=0" or "21;l=0". You have mixed concatenation, single quotes and double quotes together. Those conditions are going to try to match on the string "21;n='.0.'" which is not being passed in your url.

else if ($pg=="21;n='.$get_numbers.'") { echo 'Numbers...'; }

should be revised to

else if ($pg=="21;n=$get_numbers") { echo 'Numbers...'; }

In double quoted strings php will parse variables. If you use single quotes you need to concatenate your variable. e.g. else if ($pg=='21;n='.$get_numbers) { echo 'Numbers...'; } Both of these statements will yield the same result and should both work correctly.

Solution found...

  $pg = (int) $_GET[ 'page' ];
  if ($pg == '21' && isset($_GET['n']) && $_GET['n'] == $get_numbers)
  { 
    echo 'Numbers...';
  }
  elseif ($pg == '21' && isset($_GET['l']) && $_GET['l'] == $get_letters)
  { 
    echo 'Letters...';
  }
  elseif ($pg == '21')
  { 
    echo 'Regular...';
  }

Just need to figure out how to make it work on a site that doesnt use ?page=

Like right now the above code works on sites where the addres is like index.php?page=21 but I need to now also make the above work on a site which looks just like file.php

@MoreBloodWine: Since you have found the solution to the problem, please mark the post as solved.

Srry, forgot about this...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.