Php Hyperlink not Fuctioning Correctly

September 26, 2011 at 14:50:52
Specs: Windows 7, I7 4GB
I have a MySQL table made up of several fields, 2 of which are for the url, one field is labelled 'prefix' which contains 'http://' and the other field contains the remaining section of the url i.e. www.midchesh.ac.uk or 'shop.niace.org.uk/adultslearning-free-sample.html'.

I have echoed the info out onto the screen but now want to connect the 'prefix' and 'url' fields from the database to enable the user to click on the link and go to the destination.

Unfortunately at the moment when I click a link it keeps the current url in the address bar and just tags the new url to the end which obviously causes an error.

The script below is the php I currently have, I would be grateful if someone could advise as to where I have made the error.

Thanks

$query = "SELECT * FROM resources";
$result = mysql_query($query) or die(mysql_error());
echo '<h3>Websites and Journals</h3>';
while ($row = mysql_fetch_array($result))
{

echo $row['id'] . '<br />';
echo $row['type'] . '<br />';
echo "" . $row['prefix'] . $row['url'] . "";
echo '<br />' . $row['notes']. '<br /><br /><hr /><br />';
echo "<br />";
}


See More: Php Hyperlink not Fuctioning Correctly

Report •


#1
September 27, 2011 at 06:24:14
solution

echo "<a href='".$row['prefix'].$row['url']."'>".$row['prefix'].$row['url']."</a>";

However when I try to put . 'target="_blank' in the scenario everything falls apart.

Can anyone advise as to the solution please?

Thanks in advance


Report •

#2
September 28, 2011 at 00:15:49
Keep your use of quotes and apostrophes consistent. I see that you alternate and that could be causing you problems. I use quotes for HTML and apostrophes for PHP, so this is what I came up with:
echo '< a href="' . $row['prefix'] . $row['url'] . '" target="_blank">' . $row['prefix'] . $row['url'] . '</ a>';

Note that I intentionally added spaces to the opening and closing anchor tag so you can actually see the code on this forum.

Apologies if I don't respond to your reply immediately. I don't check this site daily, but you're welcome to PM me as a reminder.


Report •

#3
September 28, 2011 at 05:02:35
Thanks for that, worked fine.

Report •

Related Solutions

#4
September 28, 2011 at 12:50:55
I'm happy to help.

Apologies if I don't respond to your reply immediately. I don't check this site daily, but you're welcome to PM me as a reminder.


Report •


Ask Question