Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Jquery/Php help
Index -> Programming, PHP -> PHP Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
nonamedude




PostPosted: Sun Apr 10, 2011 12:56 pm   Post subject: 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");
                }
            )
            }

        )


The php script that reads the mysql database

code:
<?php
require ("connect.php");
mysql_select_db("article_info") or die ("Could not select Database");
$extract = mysql_query("SELECT * FROM articles")or die ("Not working");
//$numrows = mysql_num_row($extract);
while ($row = mysql_fetch_assoc($extract)) {
    $id = $row['id'];
    $article = $row['article'];
    $thumbsup= $row['thumbs_up'];
    $thumbsdown = $row['thumbs_down'];
    $date = $row['date_time'];
    $username = $row['username'];
   
}

;
$thumbsup++;
mysql_query("UPDATE  `article_info`.`articles` SET  `thumbs_up` = $thumbsup");
echo $thumbsup;
//$Response = array( 'Id' => $id,  'Article' => $article,'ThumbsUp' => $thumbsup);


exit;

?>


And this is where it is being printed to

code:
         <tr>
                            <td>
                                <table class='thumbs'>
                                    <tr>
                                        <td>
                                <a id = 'hello'>
                                 <img id='up' name=imgName border=0 src='images/thumbup_gray.png'
                                   ></a>
                                 </td>
                                <td>
                             <div id='c'>0</div>


                </td>
                </tr>
Sponsor
Sponsor
Sponsor
sponsor
nonamedude




PostPosted: Sun Apr 10, 2011 2:21 pm   Post subject: Re: Jquery/Php help

*bump*
Tony




PostPosted: Sun Apr 10, 2011 2:38 pm   Post subject: 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",
...

make sure to do properly escape any such arguments.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
nonamedude




PostPosted: Sun Apr 10, 2011 2:43 pm   Post subject: 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




PostPosted: Sun Apr 10, 2011 2:58 pm   Post subject: RE:Jquery/Php help

Presumably you want the id of the current page you are on, right?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
nonamedude




PostPosted: Sun Apr 10, 2011 4:28 pm   Post subject: 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




PostPosted: Sun Apr 10, 2011 4:45 pm   Post subject: 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?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
nonamedude




PostPosted: Sun Apr 10, 2011 4:56 pm   Post subject: 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.
Sponsor
Sponsor
Sponsor
sponsor
Amailer




PostPosted: Sun Apr 10, 2011 5:08 pm   Post subject: RE:Jquery/Php help

Label each tag for which ID you want to get, with a common class and do something like

code:

<a id="myid" class="common"></a>


then do something like:
code:

$('.common').bind('click', function () {
var myid = $(this).attr('id');
});
nonamedude




PostPosted: Sun Apr 10, 2011 5:17 pm   Post subject: Re: Jquery/Php help

ahhhh i see, thanks a lot!!!
Display posts from previous:   
   Index -> Programming, PHP -> PHP Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: