Silent Pond Silent Pond - 7 months ago 17
PHP Question

Rediricting url dynamically from dynamically populated links

a mysql database has following three columns:

id url_href url
1 yahoo http://www.yahoo.com
2 google http://www.google.com
3 bing http://www.bing.com


i use the following query to get the value

mysql_select_db($database_XYZ, $XYZ);
$query_urlencoder = "SELECT id, url_href, url FROM sites WHERE id >0 ORDER BY id DESC";
$urlencoder = mysql_query($query_urlencoder, $XYZ) or die(mysql_error());
$row_urlencoder = mysql_fetch_assoc($urlencoder);
$totalRows_urlencoder = mysql_num_rows($urlencoder);


the href tag

<a href="redirect.php?encodeurl=<?php echo $row_urlencoder['url']; ?>" target="_blank"><?php echo $row_urlencoder['url_href']; ?></a>


populate links on page dynamically based on repeat region like,

yahoo
google
bing


and clicking above links take the users respectively to

http://www.examplecom/redirect.php?encodeurl=http://www.yahoo.com
http://www.example.com/redirect.php?encodeurl=http://www.google.com
http://www.example.com/redirect.php?encodeurl=http://www.bing.com


but those actually aren't redirected to the respective url like

http://www.yahoo.com
http://www.google.com
http://www.bing.com


how can i redirect the href links to the the above url in this case? any suggestion or reference shall be thankfully appreciated.

Answer

Use urlencode php function

redirect.php?encodeurl=<?php echo urlencode($row_urlencoder['url']); ?>
Comments