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
Share on other sites

I don't actually want to use JS. I'm not quite familiar with it. I have some basic knowledge in PHP so it's easier for me to implement things in PHP. How do you suggest I go about it? Does anybody else have an idea?

 

 

Thanks,

Karen

Link to comment
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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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