Welcome Guest, Not a member yet? Register   Sign In
Simple vote up/down?
#1

[eluser]Unknown[/eluser]
I've been trying for hours...

How would I go about creating two buttons/images which are labeled "up" and "down"?
Upon clicking one of them, they will launch a SQL query that will add +1 to the current row?

For example:
Current up: 8
Current down: 3
*User clicks up button/image*
*mySQL does it magic*
Current up: 9
Current down: 3
#2

[eluser]ywftdg[/eluser]
I would say the typical, basic php method, would be to pass a number (or value) through the url, then use the URI helper to get those values and run your query. You could also use a more modern approach, if you need/want it, and use ajax.
#3

[eluser]Unknown[/eluser]
[quote author="ywftdg" date="1218441891"]I would say the typical, basic php method, would be to pass a number (or value) through the url, then use the URI helper to get those values and run your query. You could also use a more modern approach, if you need/want it, and use ajax.[/quote]Yea, I wanted to do ajax. Would it be possible to help me out on this? If ajax is too much, we can go for the non-ajax version.
#4

[eluser]Sumon[/eluser]
Very easy with AJAX also. Use former solution by ajax.
Lets say your url is: www.mysite.com/counts/3 (You have tested this works fine when you hit this url directly)
For example consider this is your AJAX function.
Code:
[removed]
    function CreateNewHttpObject()    //Create an Instance of HTTP request.
    {
        var xmlHttp=null;
        try{          // Firefox, Opera 8.0+, Safari
          xmlHttp=new XMLHttpRequest();
        }
        catch (e){          // Internet Explorer
            try{
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }
              catch (e){
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
          }
        return xmlHttp;
    function DisplayOutput (divID)
    {
        var ObjHttp= new CreateNewHttpObject();
        if(ObjHttp)
        {
            var obj = document.getElementById(divID);
            ObjHttp.open("GET", 'www.mysite.com/counts/3');
            ObjHttp.onreadystatechange = function()
            {
                if (ObjHttp.readyState == 4 && ObjHttp.status == 200)
                    obj[removed] = ObjHttp.responseText;
            }
            ObjHttp.send(null);
        }
    }

Simply call the function from your buttons/images which are labeled “up” and “down”
Code:
DisplayOutput('divwhereyourCurrentup8show')
I Hope you get my point.




Theme © iAndrew 2016 - Forum software by © MyBB