Jump to content

Replacing links with dynamic data


karenn1

Recommended Posts

Hey everyone!

 

Please have a look at this site: http://www.yellowpages.co.za

 

On the right there are business sections you can click on. Once in a section, there is details for all the relevant companies. Have a look at the link for "Phone". When you click on it, the link completely disappears and is replaced with the company telephone number. How can I use PHP to do this? I want to use this primarily on my site to keep track of how many times someone clicked on that link. Would I be able to do that as well?

 

 

Thanks,

Karen

Link to comment
https://forums.phpfreaks.com/topic/61532-replacing-links-with-dynamic-data/
Share on other sites

Ok, i a m a noob, so this may not work.

 

For each of the phone links i would submit them to the page using PHP_SELF. Then apply an id and a display variable to the url so each link looks like this,

 

<a href="link.php?id=1&display=num">Phone</a>

 

So then you can use php to either show the actual text phone or the phone number with an if statement, as shown below,

 

<?php
if ($_GET[display] = "num")
{
echo "080989779";
}
else
{
echo '<a href="link.php?id=1&display=num">Phone</a>
}
?>

 

then to make it dynamic have a database set up with a phone numbers table with the fields id and phone. Then you can pull the correct number from the database using the id field.

 

Hope this helps.

Okay, so i've tried the code given above and I managed to reference info from the database but clicking on the link doesn't do anything. The link looks as follows:

 

<a href="phone_link.php?id=<?= $rs_prop["id"]; ?>&display=<?= $rs_prop['home_no']; ?>">Phone</a>

 

$rs_prop is the variable where all the info of the database is stored. This gets called via a SQL statement. The above code returns the following:

 

phone_link.php?id=1&display=9135756

 

The principle works fine. I have a list of clients and for each one when rolling over the above link it displays the correct ID and phone number. I'm still struggling though. Can can I get it, when you click on the above link, the link itself gets replaced with the phone number? I don't want the page to go anywhere. The if statement supplied by nicangeli gives me errors. Can anyone else help?

 

Any help would be appreciated. Thanks!

 

Karen

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.