dimanche 25 décembre 2016

How to define condition based on get url value

When a user clicks on "List View" link then I want to show them the "List View" HTML and when they click on "Grid View" I want to show "Grid View" HTML. I've defined the following links to click-

<a href="?view=list">List View</a> <br>
<a href="?view=grid">Grid View</a>

Then I defined the following condition with PHP get method to show user the desired output-

<?php
if( isset( $_GET['view'] ) == 'list' ){
  echo "This is List view";
}else if( isset($_GET['view'] ) == 'grid' ){
  echo "This is Grid view";
}

This condition is not working. If I change "view" to "view_1" and "view_2" from URL then my condition is working as well.

<?php
if( isset( $_GET['view_1'] ) == 'list' ){
  echo "This is List view";
 }else if( isset($_GET['view_2'] ) == 'grid' ){
  echo "This is Grid view";
 }
?>
<br>
<a href="?view_1=list">List View</a> <br>
<a href="?view_2=grid">Grid View</a>

But I don't want to change the "view" key. I just want to keep the same key and different value for both URL to do the conditional statement.
Is it possible?

Aucun commentaire:

Enregistrer un commentaire