kyleabaker Posted November 28, 2006 Share Posted November 28, 2006 Sorry if the title is confusing but I didn't know how else to word it. I am trying to find a way to basically keep count of links on my website that are clicked so users can see the most used links. I have all of the links in a database and the attributes for each entry include link number, number of clicks, link url, link name, and a type so I can organize them when the page is generated. I thought there might be a way to append something on each link on the pages so they are like...http://www.mydomain.com/linkredirect.php?link=x...where the linkredirect.php page will load with minimal elements and use the link number in the database ("x" in the url) to navigate to that link and using the link number it can at the same time increment the link clicked value in the database. The only wall I've run into is how can I make the page generate and write and redirect tag into the header of the file that will let me use the link=x value to find the link in the database, increment the click count and then write the redirect tag to the document plugging in the url that it fetches? Any small examples would be very helpful.Thanks in advanced Gurus, haha. Link to comment https://forums.phpfreaks.com/topic/28692-using-variables-that-are-appended-to-urls/ Share on other sites More sharing options...
fert Posted November 28, 2006 Share Posted November 28, 2006 $_GET[link] will have the varible Link to comment https://forums.phpfreaks.com/topic/28692-using-variables-that-are-appended-to-urls/#findComment-131317 Share on other sites More sharing options...
kyleabaker Posted November 28, 2006 Author Share Posted November 28, 2006 Awesome, exactly what I was looking for. Thanks! Link to comment https://forums.phpfreaks.com/topic/28692-using-variables-that-are-appended-to-urls/#findComment-131321 Share on other sites More sharing options...
kyleabaker Posted November 28, 2006 Author Share Posted November 28, 2006 Is it possible for me to increment the link clicks using this method? If so I might be able to bypass using a linkredirect.php page all together which would be much better! I'm just not positive if this javascript function will do what I need it to do. It is called within the onClick event of the url (onClick="linkClick(x)"). < - script type="text/JavaScript" language="JavaScript"> function linkClick(n) { <-?php $query ="SELECT number,visits"; $query.=" FROM links ORDER BY number ASC"; $result=mysql_query($query); while (list($number,$visits) = mysql_fetch_row($result)) { if ($number==n) { $result=mysql_query('UPDATE links SET $visits=$visits+1'); } } ?> } < / - script> Link to comment https://forums.phpfreaks.com/topic/28692-using-variables-that-are-appended-to-urls/#findComment-131348 Share on other sites More sharing options...
trq Posted November 28, 2006 Share Posted November 28, 2006 php (serverside) cannot be run within javascript (clientside) without having javascript make another request to the server.Of course you could use some simple [url=http://marc.theaimsgroup.com/?l=php-general&m=112198633625636&w=2]ajax[/url] trickery to have javascript make this request almost silently. Link to comment https://forums.phpfreaks.com/topic/28692-using-variables-that-are-appended-to-urls/#findComment-131353 Share on other sites More sharing options...
kyleabaker Posted November 28, 2006 Author Share Posted November 28, 2006 Thanks thorpe. I'll look into it.Also, thanks fert. using the GET command that you helped me with I've halfway accomplished my goal, haha. I'll be back if I get stuck. Thanks all! Link to comment https://forums.phpfreaks.com/topic/28692-using-variables-that-are-appended-to-urls/#findComment-131384 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.