mysql stuff when click on link then go to link - php

I have a phpBB forum, some posts contains Links... I want to count how many times the link on the post has been visited...
I think that catching the "click" on the link, make php and mysql stuff and, then after all, go to the external link is the best way ... but I dont know how to do that.
Its possible to interrupt the link click, modify some things and then load de link as always? (maybe using ajax or jquery)
A link example could be:
www.google.com
The mysql table called phpbb_likes contains:
Like_id
Post_id
User_id
Like_time
I know how to add a new like using something like this:
Insert INTO phpbb_likes ("Post_id","User_id","Like_time") VALUES ("2355","45","1343546456");
But the problem is interrupting the link redirecting to make that sql query
Any Idea?
thanks

Related

Auto-update Posts without refreshing

I'm currently only using PHP to take user submissions, put them in a database, and echo them out on a page using SQL to select from a table, such as comments. I need a system that will automatically update comments without refreshing the page like on YouTube. The less the user has to manually update, the better.
I want it to work pretty much exactly how YouTube and Twitter function, where it'll say "x NEW COMMENT(s)" and clicking that updates everything.
My teacher recommended a JQuery function, but I don't have any background in that language so I don't know where to begin looking.
I'm at a complete impasse. I will update this if you guys need additional information to aid in my search.
You are looking for AJAX
You will need a HTML page with jQuery/AJAX that calls another PHP page. In that PHP page you do the DB request and then ideally return the data as JSON so that your frontend part can display it to the user.
As every one says, AJAX is the way. You can find a simple blog I did on it here.

Record what user has clicked

I want to recognize (with php, mysql) and save which blog entries a user has clicked. Like, I have tech entries, lifestyle entries etc. and I want to record which entries a user is interested in, so that I could provide just these entries for him!
So you know what I mean? I wonder if there are any tutorials or something.
Thanks, dartox.
When they are opening the page, just store the id of that blog entry in a table. Down the road, you can do something as simple as COUNT (*) on that table for that user, sort by category, and find out what category they're mostly interested in. You can get really complex for recommendations, but this is one of the more simpler ways of accomplishing it. Hope that helps!
I like to use www.statcounter.com
So create a page: tracker.PHP, and in it put the tracking code from statcounter (or Google analytics for that matter)
On every page with links I'd put a hidden iframe with an id="tracker" and no src just yet, :
<iframe id="tracker" style="visibility:hidden;height:0px;width:0px;" frameborder="0">
</iframe>
Then every link I'd do something like:
<a href="/some_tech_article.php"
onclick="document.getElementById('tracker').src='/tracker.php?location=techarticle';">Tech Articles
</a>
So everytime someone clicks a link, the iframe will invisibly load your tracker.php page and send any information you want to send in the URL (as a $_GET php variable)....from there you can track and save whatever information you'd like into a database or whatever.
You can use this trick to send information behind the scenes when users click things, without switching pages. I use this to track clicks, and update tables in mysql.
If you need me to give you a better example let me know!

php report button

I am working on a search script and on each search result I want a report link button. I am not sure how to make one. I have looked on google for answers but cannot come up with anything. Can anyone give me an idea of what to do? or does anyone know where there is an example of this? I plan on using the link id and making a new table on mysql to send reports to. I am just looking for a basic button to send reports to mysql I am just not sure what would be the best way to do it. I have the data for the link id's I just need to be able to report it to a new table I am assuming. Any suggestions or examples are very appreciated. Thanks.
Chris,
First you will want to create that new table in your database to capture this information. Lets assume to you will have the following fields (very basic, you may want to add more): ReportId, LinkId, DateReported. ReportId is our primary key, LinkId is the ID you reference in your question and the DateReported is the server time we logged the transaction.
With this table created you are going to want to create a new php page, lets call it report-link.php. You are going to want to make this page accept a querystring variable called linkid (accessible in the $_GET[] collection). In the code of this page you will want to write a SQL query that inserts the value of the linkid parameter into the new link report table in the database (along with the date()).
On your search page you will be able to have users report an entry by clicking a link with the href of /path/to/report-link.php?linkid=<?php echo $link_id; ?>
Please note this example is very simplistic in nature, and offers no security for spamming, pleasant end user experience after they click the link, but this is the process you will want to follow in setting this feature up. After you have it working you can spruce up the experience for your users.

Update a record with a single click

I am working on a CMS for a website using PHP and MySQL and have been asked if it is possible to 'publish' articles just by clicking on a button?
To make things clear, the articles may have already been entered into the database but not identified as being ready for publication. Articles for the site have a column in the db called _'pub'_, which is an ENUM('n','y'). I have created a page which lists all articles by section, article heading, date and published.
If _'pub'_ is 'y', published displays YES, otherwise it displays NO
I have created an additional page that changes the state of _'pub'_ so that it works by clicking on the Yes or No for published, but wondered if there was a way of changing the status of _'pub'_ using javascript rather than an additional page.
I look forward to hearing any suggestions
Just use jquery like this
$.post("/submit.php","title='Title of post'&content='PostContent'", function(d){
$(".output").html(d);
});
What that basically does is, sends the content to submit.php with ($_POST['title'] and $_POST['content']).. and then returns the output in a div with the classname output
And everything happens with a single click on the same page
You want the users to stay on same page, is that it?
Use ajax/jQ to:
submit articleid that should be published
on request-completion, change image/text in list from "no" to "yes"
http://net.tutsplus.com/tutorials/javascript-ajax/5-ways-to-make-ajax-calls-with-jquery/
is a good start.
regards,
//t

Best way to know when users register duplicated links (MYSQL + PHP)

so i have a page where a user can submit his own links
i dont want to make a script that do everything automatic, i just want to make a page where, when the .php find a possible duplicated link, i get a warning like "ID 22 could possible have the same link as ID 738"
i only need like the query to do that...if its possible with that..i can only use php and mysql
if its too expensive (memory, cpu..) i can make like a submit button then when pressed generates like a report
ps: just to be clear, im not showing the message to the user, is something im going to put at my admin cp..and its not comparing "link 1" to "link 2" but searching the entire database
thanks
Your best bet would be to have a query that runs when new links are submitted. It could do something like this as a basic example:
SELECT * FROM links WHERE url = ""
If that returns results, then you have a dupe which can either be prevented from being inserted into the database, or simply flagged somewhere for review.
If you want to know which links are used by more than 1 ID, you could do something like this:
SELECT link,COUNT(id)
FROM link_table
GROUP BY link
HAVING COUNT(id) > 1

Categories