-1

Hello everyone I am a newbie and a student and there is a code in PHP that I want to have on my PHP.

enter image description here

So what I want is if I click the URL it should popup a new window. I know how to do it in a button but I have no idea how to do it using echo.

PS: THIS IS THE CODE I WANT TO REPLACE

echo"<td><a href=update.php?primary=".$row['ID']."'>Update</a>";

PS: Please correct me / Teach me. PS: I am now able to open it in a new window but the problem is I am not able to get the primary.

Here is my code: echo"<a href=update.php target=popup onclick=window.open('update.php','popup','width=500,height=500');return false;?primary=".$row['ID'].">Update ";

Lance
  • 11
  • 1
  • Hi ! Can you provide a [minimal code sample](https://stackoverflow.com/help/minimal-reproducible-example) showing what you tried ? – Hollyol Oct 16 '20 at 10:30
  • Please put efforts in learning basics of PHP, JS. This is not a platform to teach you. – Manish Pareek Oct 16 '20 at 10:30
  • This is trivial to research. What did you try? Here's the answer: https://www.thesitewizard.com/html-tutorial/open-links-in-new-window-or-tab.shtml (P.S. It's a HTML issue, nothing to do with either Javascript or PHP) – ADyson Oct 16 '20 at 10:32
  • 1
    This is also a duplicate of [How can I make a HTML a href hyperlink open a new window?](https://stackoverflow.com/questions/13335954/how-can-i-make-a-html-a-href-hyperlink-open-a-new-window) and many other similar questions. – ADyson Oct 16 '20 at 10:37
  • P.S. As a general point, since you're new I suggest you take the [tour](https://stackoverflow.com/tour) which you were recommended to do when you signed up for StackOverflow (but I can see from your profile that you haven't) and read the [How To Ask](https://stackoverflow.com/help/how-to-ask) guide. That way you'll have a better idea of what a good question looks like, and therefore improve your chances of asking meaningful questions and getting useful answers in future. These resources are here to help you have a good experience on StackOverflow, so please use them. Thanks. – ADyson Oct 16 '20 at 10:38
  • What **exactly** are you looking for? A popup, or opening a new window? Nevertheless, both ways are not connected to PHP in any way – Nico Haase Oct 16 '20 at 13:49

2 Answers2

1

Please do research before asking a question.

Ether way, I suggest over all you'd visit a site called W3Schools, its very basic, but provides with pretty useful stuff.

In this case you need to add the attribute "target", to _blank If I am not mistaken. You can read about what kind of target attribute options you can do hare: https://www.w3schools.com/tags/att_a_target.asp

Since you are a new contributor, I suggest looking trough that site at minimal before going with a post.

Added the solution with explanation.

echo"<td><a href=update.php?primary=".$row['ID']."'>Update</a>";

Change it to:

echo"<td><a target='_blank' href='update.php?primary=".$row['ID']."'>Update</a>";

By the way, you forgotten to add a qoute on your href attribute, this might've been causing some problems.

The target is a "<a>" tag attribute, its just html, echo from PHP side just acts as a renderer from php files. So whatever you put in your echo will render with HTML. Its important to add <head> and <html> tags so it would render like a full HTML document, just having php tags. It is wise to separate these things to make a proper framework A.K.A - using template system and leaving PHP parts to be only calculations from endpoint (Server side). I'd advise you to learn some sort of framework like Symfony based frameworks (Laravel for example). It will be a bigger hustle to learn, but you would learn it the right way and would know way more about these things from that.

Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97
Thomas J.
  • 593
  • 8
  • 21
  • I did try looking it at w3school but it didnt provide on how to use it on "echo" or maybe it did I just did not understand. Thats why I have no choice but to look for help here. – Lance Oct 17 '20 at 14:26
  • @Lance updated my answer. Check your href qoute aswell. – Thomas J. Oct 19 '20 at 07:30
0
     echo"<td><a target=_blank href='update.php?primary="'.$row['ID'].'"'>Update</a>";

target=_blank is what you want to open a new window from a link href.

Kylie
  • 11,421
  • 11
  • 47
  • 78