Jump to content

target attribute in php hyperlink


Recommended Posts

I have researched the subject and found a few 'solutions' for my problem but cannot get it to work (I looked at ones in this forum).
I have php while loop that uses variables for db values and wrapped inside <a></a> tags that work as desired. What I want to have the link open in a new tab.
Here is the code I am working with:

	//loop to collect and output db data as hyperlink with target="_blank"
		while($row = mysqli_fetch_assoc($result)) {
		//output data from each row
		echo "<a href='".$row[link]."'>&diams;&nbsp;&nbsp; ".$row[title]."</a><br>";


Link to comment
Share on other sites

requinix - I have been working on this for a couple of days. I have researched and tried many many options to no avail. I just saw Barand's latest post with an updated corrected code. Thank you for following up.

I tried Barand's code and it worked great. I never thought about putting it in the code there.

Edited by Wal-Wal-2
Confirmation that code worked.
Link to comment
Share on other sites

ginerjm - Thank you. I am not sure why the {}'s are around the array ( {$row['link']} ) code. I am really interested in learning. If you can, and it is appropriate here, can you explain it to me? I am new to the forum so not sure what the protocol is. Thanks again.

Link to comment
Share on other sites

The braces are required when embedding complex variable names (an array element) inside other things.  Without them you would get a syntax error.  You could use concatenation (dots) to avoid this but with the braces you can skip the concatenating and just compose one contiguous string here.  

The thing I wanted you to note was the quotes on the array indices.  A Key thing!

  • Great Answer 1
Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.