
-----------------------------------
nonamedude
Sun Apr 10, 2011 12:56 pm

Jquery/Php help
-----------------------------------
Hey guys, 

I recently started using jquery, and i have come across a problem for the project i am doing.

I am trying to imitate the rating system of youtube for my new site. This site is one that has articles

So once a user log ins, i want to be able to read the amount of thumbs up./down the user has for a particular article. So far, i have been able to get this to work. But the problem is, I dont know how this would be possible if there are several articles with a unique id for each of them.

This is what I have so far

The function that changes the image and increments the value 

 [code]$(document).ready(function()
            {
                var check = 0;
                $('a#hello').one("click", function()
                {
                  
                    $.get(
                    "http://localhost/test/folder/includes/mqsql.php",
                    null,
                    function(data) {       
                        // alert(data);
                        var value = data;
                        // $('#c').replaceWith(value);
                        $('#c').html(value);
                          
                    }
                  
                );
                    $("#up").attr("src","images/thumbup_blue.png");
                    $("#down").attr("src","images/thumbdown_gray.png");
                     
                }
               
            )
                $('a#two').one("click", function()
                {
                    $.get(
                    "http://localhost/test/folder/includes/mqsql2.php",
                    null,
                    function(data) {
                        // alert(data);
                        var value = data;
                        //$('#c').replaceWith(value);
                        $('#c').html(value);
                        // alert (value);

                    }
                );
                    $("#down").attr("src","images/thumbdown_red.png");
                    $("#up").attr("src","images/thumbup_gray.png");
                }
            )
            }

        )[/code]

The php script that reads the mysql database

[code][/code]

And this is where it is being printed to 

    [code]         
                            
                                
                                    
                                        
                                
                                 
                                 
                                
                             0


                
                [/code]

-----------------------------------
nonamedude
Sun Apr 10, 2011 2:21 pm

Re: Jquery/Php help
-----------------------------------
*bump*

-----------------------------------
Tony
Sun Apr 10, 2011 2:38 pm

RE:Jquery/Php help
-----------------------------------
you can make a get request with arguments passed back to php
[code]
$.get(
"http://localhost/test/folder/includes/mqsql.php?id=42",
...
[/code]
make sure to do properly escape any such arguments.

-----------------------------------
nonamedude
Sun Apr 10, 2011 2:43 pm

Re: Jquery/Php help
-----------------------------------
Oh, i see what you mean, but how do I know which id to request, since the id is in php. Is there a way to pass the id from php to the jquery function?

-----------------------------------
Tony
Sun Apr 10, 2011 2:58 pm

RE:Jquery/Php help
-----------------------------------
Presumably you want the id of the current page you are on, right?

-----------------------------------
nonamedude
Sun Apr 10, 2011 4:28 pm

Re: Jquery/Php help
-----------------------------------
Not the id of the page i am on but the id what i clicked, for example, if an image has an id, when i click it, i want that id to be sent to jquery.

-----------------------------------
Tony
Sun Apr 10, 2011 4:45 pm

RE:Jquery/Php help
-----------------------------------
Right. Lets try it this way -- if the image to be clicked was just a regular link, it would still need to know the ID to go to the right page, correct? How would you "send" an id to that link tag?

-----------------------------------
nonamedude
Sun Apr 10, 2011 4:56 pm

Re: Jquery/Php help
-----------------------------------
I am not sure what you meant but,

$('#c').html(value); 

The 'c' above is the id of the div that i am replacing the value in. If there are more than one divs, then the id has to be changed based on what the user selects. So i need to pass the id on to the function, cause right now, I have just written the c manually.

-----------------------------------
Amailer
Sun Apr 10, 2011 5:08 pm

RE:Jquery/Php help
-----------------------------------
Label each  tag for which ID you want to get, with a common class and do something like

[code]

[/code]

then do something like:
[code]
$('.common').bind('click', function () {
var myid = $(this).attr('id');
});
[/code]

-----------------------------------
nonamedude
Sun Apr 10, 2011 5:17 pm

Re: Jquery/Php help
-----------------------------------
ahhhh i see, thanks a lot!!!
