Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

how to use kodus with php

hi... I ran into kudos today. It was a nice job....

how should I use it in a php website...

use it like google+ or facebook count on my own site... how should I store numbers of "kudos" ?

[It's only for some pages]

thanks

;)

6 Answers

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

You'll want to set up some kind of web service that the kudos JavaScript can send data to, and then that web service will need to store the data in something like a database. Then, when the PHP page loads the next time, you'll want to retrieve the data from the database with PHP and echo it to the screen.

Does that help?

Yeah... Thanks Randy

But my problem is that i don't know how to write the code to do these things... I mean the database part...

I've heard of AJAX (far from the part that @Jason teaches it)... Should it be something Like that?

any code hint?

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

The code for this is pretty tricky if you haven't done it before. I plan to cover something like this in a future video tutorial. I'll try to find a good resource for creating a PHP web service that can be accessed with an Ajax request.

Hi,

thanks... I'll wait for the video...

I'm making progress : for Some reason I decided to have a input text [number ] ( which people insert how many people around them are actually doing the suggestion in the text ) [called as "count"] & a submit button :

There is a database called "el" , which contains two tables "el_c", "el_f".

in "el_c" there are 2 fields : "elc_id" , "elc_count".

and in "el_f" there are 2 fields : "elf_id" , "elf_sum"

Here's my code : [in a page called add.php]

$count = $_POST["count"];
$link = mysql_connect("localhost","root","");
mysql_select_db("el",$link);
$sql = "INSERT into el_c (elc_count)"."value ($count)";
mysql_query($sql,$link);

now I want to UPDATE the first row of table "el_f" with the SUM of all "elc_count" datas from "el_c" table...

I don't believe it would be too hard!

thanks in advanced

;)

Hi

This should work... but I don't know why it doesn't...

I made it a little better too...

$count = $_POST["count"];
$link = mysql_connect("localhost","root","");
mysql_select_db("el",$link);
mysql_query("INSERT into el_c (elc_count) value ($count)",$link);
mysql_query("UPDATE el_f SET elf_sum = SUM(elc_count) FROM el_c WHERE elf_id='1'",$link);

It'd be really happy to be helped.

;)

thanks

Here it goes :

mysql_query("UPDATE el_f SET elf_sum = (SELECT SUM(elc_count) FROM el_c WHERE elf_id=1)",$link);

It just needed a "SELECT" ....