<a> tag + php

时间:2016-05-22 08:32:57

标签: php

I have a requirement where I am looping through some objects to create tags and have to open another page after setting some session variables.

    for ($i = 0, $count = count($result_array->items); $i < $count; $i++)
    {
        $item = $result_array->items[$i];
        ?>
        <a href="" onclick="<?php itemSelected($item); ?>">View more</a>            
        <?php
    }

    function itemSelected($argItem)
    {
        $_SESSION['selected_item'] = $argItem;
        header('Location: ' . 'item-details.php');
    }
    ?>

It seems that for every loop rotation, the itemSelected() function is firing up. So basically when I'm loading this page, it is getting redirected to item-details.php.

Why is it so and how to handle that?

0 个答案:

没有答案