How to update many url links

Hi there,

I have many url links in a database that I want to update so that when the link is clicked, it opens a new page and keep the existing page open. so using the target=“_blank” should solve the issue but I have thousands of links and need to add this bit to each link is time consuming. I was thinking of using the update table set ur link to the open new window bit , but this will replace the whole link with the open window bit which is not what i want. Is there a possible way of achiving this ?

the good news is all the links end with ‘3Dno’ as shown below:;

Thanks in advance

Ok I found where the url is inserted in the database. This is the bit that inserts the url link in the table. Is there a way of manipulating this to add the target bit?

$result = mysql_query(
"`deal`='" . escape($package["dealdetails"]) . "', " 
"`buyurl`='" . escape($package["url"]) . "', " 

You’ve added target="blank" as part of the link, rather than an HTML attribute.

Is the HTML for the link stored in the database, or just the URL?

Does the database hold:

Or: <a href="">Google</a>?

create a temp table… export all the link out of the original table… explode it … clean it up do what you gotta do to the links and the re-import it into the table.

simple… there’s bunch of ways to do this.

Unfortunately, its a data feed that comes from a third party supplier which I have no control and they cant change it, so i have to add it my self. I know its not helpful from their part but I need to get it sorted somehow.

UPDATE table
SET url = CONCAT(url, ' target="_blank" ')

Why update the database?
Why not change the bit of code where you get the urls from the database and display them as links?

If the output page scrubs the database entries before posting them, you’ll -have- to change the code. If it doesnt, you can do it the way they said, except you’ll have to move that trailing " to before the space.

The code reads
<a href=“$somenamehere”>

Resulting in
<a href=“quack.php”>

if you inject what Guido said, you get
<a href=“quack.php target=”_none"">
Which… doesnt work.

If you inject " target=“_none , you get:
<a href=“quack.php” target=”_none">
Now that looks right…

Guido2004 is, as always, right. :slight_smile:

Edit your code to create the required href, if you need help to do this, just ask and post the code you use currently to display the link in question.

Like I told you before, I think it should be better to change the code that creates the link, instead of updating the database

Good point. It holds it like:
so there is no href

Ok Just to clarify: I do not have any control over the link format, it gets stored in the database like this.

When the url link is rendered on the web page, it is displayed this way: with 2 single quotes. One at the beginning and one at the end. this is before I apply the concat bit:

<a href=‘’>

So after adding the concat bit, it always add the target bit before the last single quote so this do not work.

<a href=' target=“_blank” '>

So the concat part needs to add the target bit after the closing single quote for it to work, just like this:

<a href=‘’ target=“_blank”>Test</a>

How do I get it to achive this? add the target bit after the single quote?


SELECT REPLACE(link,'\\'>','\\' target=\\'_blank\\'>') new_link FROM table;

Why don’t you find the bit where the url is selected from the database and turned into a link and displayed in your browser. There you should do the modification and append the target.

I got the syntax sorted by adding this:

mysql_query(“UPDATE mytable SET yurl = CONCAT(url,’ target=\”_blank\" ’ ) ");

The linkl works but it doesnt open a new window when I click the link.

I looked on the source code for the generated page and it shows the link as shown below:

<a href='templates%2FcalendarDealPage.jsp.3_A%26_DAV%3D1 target=“_blank” '>URL</a>

Does the target bit needs to be at the end of the single quote?

Thanks Guido2004

I tried it but there is a parse error
syntax error, unexpected T_STRING