...

View Full Version : Link inside echo



exzrael
11-09-2006, 03:55 PM
This is a bit of a problem for me. Now, don't hate me for my coding; im still a newbie at this :)

Before you guys check the code, this is what I would like:

Take the information from $row['link'] and make that appear in:
http://www.google.com/translate?u=http%3A%2F%2Fe61life.com&langpair=en%7Cde&hl=en&ie=UTF8

So, we remove http%3A%2F%2Fe61life.com and add the information from the database from $row['link']. Can this be done?

Fig 1 - Initiating database connection and fetching everything


<?php
$db = mysql_connect($DB_HOST,$DB_USER,$DB_PWD);
if (!$db) { die("Connection failed. Report to daniel@e61life.com.np.spam (remove .no.spam)"); }
$database = mysql_select_db($DB_DATABASE);
$query="SELECT * FROM blogs";
$query_result=mysql_query($query);

?>

Fig 2 - Displaying a table with the collected database information


<div id="table">
<br />
<center><table>
<tr>
<th><p>Title</p></th>
<th><p>Category</p></th>
<th><p>Language</p></th>
<th><p>Link</p></th>
<th><p>Translate</p></th>
<th><p>Other</p></th>
</tr>
<?php
while ($row = mysql_fetch_array($query_result)){
echo " <tr>\n<td><p>" . $row['title'] . "</p></td>\n <td><center><p>" . $row['cat'] . "</p></center></td>\n <td><center><p>" . $row['lang'] . "</p></center></td>\n <td><center><a href=\"" . $row['link'] . "\" target=\"_new\"><img border=0 src=\"" . "http://localhost/test/images/world_go.png" . "\"></a></center></td>\n <td><center><a href=\"" . $row['link'] . "\" target=\"_new\"><img border=0 src=\"" . "./images/flag_it.gif" . "\"></a> <a href=\"" . $row['link'] . "\" target=\"_new\"><img border=0 src=\"" . "./images/flag_de.gif" . "\"></a> <a href=\"" . $row['link'] . "\" target=\"_new\"><img border=0 src=\"" . "./images/flag_fr.gif" . "\"></a> <a href=\"" . $row['link'] . "\" target=\"_new\"><img border=0 src=\"" . "./images/flag_es.gif" . "\"></a></center></td>\n <td><center><img src=\"" . "./images/exclamation.png" . "\"> <img src=\"" . "./images/help.png" . "\"> <a href=\"" . $row['rss'] . "\" target=\"_new\"><img border=0 src=\"" . "./images/feed.png" . "\"></a></center></td></tr>\n";
}
?>
</center></table>
<?php mysql_close($db); ?>
</div>
</div>

bubbles19518
11-09-2006, 04:05 PM
<?
$row['link'] = urlencode($row['link']);
?>

http://us3.php.net/manual/en/function.urlencode.php

exzrael
11-09-2006, 04:22 PM
<?
$row['link'] = urlencode($row['link']);
?>

http://us3.php.net/manual/en/function.urlencode.php

Sorry to say it, but I cannot seem to implement this without getting an error. Would you/anyone mind write a quick example?

bubbles19518
11-09-2006, 09:06 PM
I posted that code to show you that you need to urlencode your url. I'm not sure if it will work but from a quick look at your code I think thats what you need to do...


$row['link'] = urlencode($row['link']);
echo " <tr>\n<td><p>" . $row['title'] . "</p></td>\n <td><center><p>" . $row['cat'] . "</p></center></td>\n <td><center><p>" . $row['lang'] . "</p></center></td>\n <td><center><a href=\"http://www.google.com/translate?u=" . $row['link'] . "&langpair=en%7Cde&hl=en&ie=UTF8\" target=\"_new\"><img border=0 src=\"" . "http://localhost/test/images/world_go.png" . "\"></a></center></td>\n <td><center><a href=\"" . $row['link'] . "\" target=\"_new\"><img border=0 src=\"" . "./images/flag_it.gif" . "\"></a> <a href=\"" . $row['link'] . "\" target=\"_new\"><img border=0 src=\"" . "./images/flag_de.gif" . "\"></a> <a href=\"" . $row['link'] . "\" target=\"_new\"><img border=0 src=\"" . "./images/flag_fr.gif" . "\"></a> <a href=\"" . $row['link'] . "\" target=\"_new\"><img border=0 src=\"" . "./images/flag_es.gif" . "\"></a></center></td>\n <td><center><img src=\"" . "./images/exclamation.png" . "\"> <img src=\"" . "./images/help.png" . "\"> <a href=\"" . $row['rss'] . "\" target=\"_new\"><img border=0 src=\"" . "./images/feed.png" . "\"></a></center></td></tr>\n";

Try that code, it should work... All I did was urlencode $row['link'] and then put it in the google translate url for the variable "u".

exzrael
11-10-2006, 05:23 AM
I posted that code to show you that you need to urlencode your url. I'm not sure if it will work but from a quick look at your code I think thats what you need to do...


$row['link'] = urlencode($row['link']);
echo " <tr>\n<td><p>" . $row['title'] . "</p></td>\n <td><center><p>" . $row['cat'] . "</p></center></td>\n <td><center><p>" . $row['lang'] . "</p></center></td>\n <td><center><a href=\"http://www.google.com/translate?u=" . $row['link'] . "&langpair=en%7Cde&hl=en&ie=UTF8\" target=\"_new\"><img border=0 src=\"" . "http://localhost/test/images/world_go.png" . "\"></a></center></td>\n <td><center><a href=\"" . $row['link'] . "\" target=\"_new\"><img border=0 src=\"" . "./images/flag_it.gif" . "\"></a> <a href=\"" . $row['link'] . "\" target=\"_new\"><img border=0 src=\"" . "./images/flag_de.gif" . "\"></a> <a href=\"" . $row['link'] . "\" target=\"_new\"><img border=0 src=\"" . "./images/flag_fr.gif" . "\"></a> <a href=\"" . $row['link'] . "\" target=\"_new\"><img border=0 src=\"" . "./images/flag_es.gif" . "\"></a></center></td>\n <td><center><img src=\"" . "./images/exclamation.png" . "\"> <img src=\"" . "./images/help.png" . "\"> <a href=\"" . $row['rss'] . "\" target=\"_new\"><img border=0 src=\"" . "./images/feed.png" . "\"></a></center></td></tr>\n";

Try that code, it should work... All I did was urlencode $row['link'] and then put it in the google translate url for the variable "u".

Works perfectly. Thank you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum