-1

I have this

 echo ' <a href=" '.$row["noti_link"] .' " class="notification-success active">';

And I want this query to run just when the user click this

mysqli_query("UPDATE ehr_noti SET noti_check=0, noti_check2=0 where noti_id = ".$row['noti_id']." ")

Any trick for this? I don't want to pass the variable via POST or GET then run the query for the appropriate link. I just want to run the query before going to the next page.
EDIT FOR THE REASON.
I have a while loop. And in my MYSQL there is a column for the text and the link. It's a notification bar. So whether if this accepted that when the user clicked on that, he will be transfered to a different link.

Noobster
  • 93
  • 11
  • 1
    html can't trigger a query. html is a client-side thing, and the query runs on the server. your browser HAS to send an http request to the server to invoke a php script which runs that query. how you invoke that http request doesn't matter - you have to send SOMETHING client->server to make this happen. – Marc B Aug 17 '16 at 19:11
  • ^ he knows what he's talking about. *"He's been around"*. – Funk Forty Niner Aug 17 '16 at 19:12
  • @MarcB couldn't they do something with a mod rewrite instead? *Thinking outloud*. – Funk Forty Niner Aug 17 '16 at 19:16
  • So there is no possible way for the query to run when the anchor link is pressed? – Noobster Aug 17 '16 at 19:17
  • @Fred-ii-: maybe, but rewriting can still only take an input url and change it to some other url. it can't split a request into two. e.g. `example.com/foo.php` becomes `example.com/run_before_next_page` AND `example.com/next page` – Marc B Aug 17 '16 at 19:17
  • @MarcB Yeah you're right. I thought Curl after, like this guy http://stackoverflow.com/q/37685972/ yet that still makes an http request. Well, I'm stumped on this one and seems to be a next to impossible task (could be an option for them though). *Giving up*. – Funk Forty Niner Aug 17 '16 at 19:27
  • @Noobster why do you want to do this, any special reason? If you told us the "real" reason, maybe we could offer an alternate solution. Remember to ping me directly, I may not still be in the question. – Funk Forty Niner Aug 17 '16 at 19:31
  • could just use a "jump" page. jump page executes the query, then redirects to the page that the link really should have pointed to. `` – Marc B Aug 17 '16 at 19:59
  • Hi, I added my special reason. – Noobster Aug 20 '16 at 15:15

1 Answers1

1

You could do it with ajax

$("#id").on('click', function(){

   $.ajax({
      url: 'pathtoFile.php',
      dataType: 'json',
      success: function(data){
          //returned from php
      }
    });
 )};

http://api.jquery.com/jQuery.ajax/

Oncodeeater
  • 156
  • 11
  • and what if the user disables JS? The OP is right back to "square one". – Funk Forty Niner Aug 17 '16 at 19:35
  • Maybe, if he doesn't want to use POST or GET, and he is going on another page, maybe he can just run his querry and add season, every next time he is coming there, refreshing page or anything you check does season exists if it does just skip query. Not sure about anything else if user is not using js or GET/POST – Oncodeeater Aug 17 '16 at 19:46