简体   繁体   中英

Assign different php value after every click

I know this is a hack, but I really need it.

I have following code:

<thead>
   <?php 
     if(isset($_COOKIE['gautasId'])) {
      $wishes = $conn->query("SELECT sa.id, sa.aprasymas, sa.poreikiai, sa.miestas, s.statusas FROM svajoniu_aprasymas sa join svajoniu_statusai s on s.id = sa.statusas where sa.senolio_id = " . $_COOKIE['gautasId']);
     }                     
     if ($wishes->num_rows == 0) {
     ?>
     <tr>
        <th>No data</th>
     </tr>
</thead>
   <?php } else { ?>
        <tr>
            <th>Id</th>
            <th>...</th>
            <th>...</th>
        </tr>
</thead>

I set that cookie value:

echo "<tr><td><span onclick=setValue('$eldId') class='fa fa-chevron-right fa-fw'></span> </span></td>";
function setValue(id) {
  document.cookie = "gautasId = " + id;
}

and this function is hit everytime I click it, but query values do not change. Is it possible to do this somehow?

This is pretty awfull code, so, consider removing the JavaScript element entirely by changing $_COOKIE to $_GET, and adding the ID to the url using a href tag.

echo "<a href='?id=$eldId' class='fa fa-chevron-right fa-fw'> ";

Then use $_GET[id] to pickup the value from the url

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM