0

I have this onclick="ShowSingleNew(299)" event for a link and it opens up a new popup, what I'd like to do is extract the 299 (which is an id of the given new item) and pass it in my php script so that that would be the item the user can read.

The php bit looks like so:

if (empty($_GET['news_id'])) { sql select .. }
else { sql select where news_id == $_GET['news_id']; }

So how can I pass this ShowSingleNew id to the next page and give it to the $_GET variable?

Xeen
  • 6,955
  • 16
  • 60
  • 111

2 Answers2

1

You have to pass the newsId using query string like url?newsId=104 format.

The basic format should be: ?strID=XXXX&strName=yyyy&strDate=zzzzz

The sample code looks like:

function ShowSingleNew(newsId) {
    var url = "Your url goes here";
    window.open(url + "?newsId=" + newsId);
    // other code
}

On php side, you could use $_GET['newsId'] to fetch the news id.

Note:

Check how to pass mutiple values in query string here: multivalue query string passing

Reference:

QueryString Structure

Community
  • 1
  • 1
0

Try to send like

function ShowSingleNew(id) {
   url = desired_url + '?news_id=' + id; 
   window.open(url , "_blank");
}
GautamD31
  • 28,552
  • 10
  • 64
  • 85