[Solved] how assign value to a variable using anchor tag [duplicate]


No you can not assign values to PHP variable using onClick (JavaScript Function), but it is possible to capture and set URL param through $_GET method.

If you are using Codeigniter, you must load CodeIgniter URL Helper Library first.

$this->load->helper(‘url’);

try below,

<?php


if(isset($_GET['view_set']) && $_GET['view_set'] == 'list') {
    $view_set = "list";
    echo "i am in list mode";
} else {
    $view_set = "grid";
    echo "i am in grid mode";

    if (@$_GET['categories'] == '1' && @$_GET['search'] == NULL || @$_GET['categories'] == '2' && @$_GET['search'] == NULL || @$_GET['categories'] == '3' && @$_GET['search'] == NULL || @$_GET['categories'] == '5' && @$_GET['search'] == NULL || @$_GET['categories'] == '6' && @$_GET['search'] == NULL || @$_GET['categories'] == '1129' && @$_GET['search'] == NULL) {
        $view_set="gird";
    }
}
?>

<label>View</label>
<a href="https://stackoverflow.com/questions/48907430/<?php echo current_url() ?>?view_set=grid" class="view_set <?= ($view_set == 'gird') ? 'grid-list-ative' : ''; ?>" data-view="gird" id="gird" >
    <i class="fa fa-th-large" aria-hidden="true"></i>
</a>
<a href="<?php echo current_url() ?>?view_set=list" class="view_set <?= ($view_set == 'list') ? 'grid-list-ative' : ''; ?>" data-view="list" id="list" >
    <i class="fa fa-list-ul" aria-hidden="true"></i>
</a>

2

solved how assign value to a variable using anchor tag [duplicate]