SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Zealot asrasrasr's Avatar
    Join Date
    Apr 2009
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ajax and php rating

    hello friends,

    I want to access rating script like this website:

    http://www.barcrawl.co.uk/pubcrawl.aspx?Crawl=20

    This rating script use ajax and asp.net. can this same script and functionality possible in php with ajax.

    Please help me.

    Thanks in advance

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,501
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Yes

  3. #3
    SitePoint Zealot asrasrasr's Avatar
    Join Date
    Apr 2009
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What script i can use.Can u give me a breif script please

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    A brief script is hardly possible, it requires a combination of CSS, JS and PHP to function. Break the application down into segments, then try to solve the issues that arise.

    If you encounter any problems, please feel free to post.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Zealot asrasrasr's Avatar
    Join Date
    Apr 2009
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Than wht should be my first step

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,501
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)

  7. #7
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    • Create a static HTML page that provides the interface you require.
    • Add AJAX functionality to post selected value to a PHP script.
    • Create a PHP script to save selected value.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  8. #8
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    I knew that

  9. #9
    SitePoint Zealot asrasrasr's Avatar
    Join Date
    Apr 2009
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have made some script u can see.

    On my html page:
    Code PHP:
    <?php 
    include("includes/config.php");
    $uid=$_SESSION['uid'];
     
     
     
    $qr1s=mysql_query("select id,vote from m4s_rating where bar_id='$uid'");
    $nums=mysql_num_rows($qr1s);
    $ctr=0;
    while($row=mysql_fetch_array($qr1s))
    {
    $ctr=$ctr+$row['vote'];
    }
    $avg=($ctr)/($nums);
    $avg=round($avg, 2);
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <script src="js/selectbarcrawl.js"></script>
    </head>
    <body>
    <div id="txtHint">
     <div id="ctl00_C1_UpdatePanel1">
    <table width='100'>
     <tr>
       <td>
               Overall Rating:<span class="RateBarTxt"><?php echo $avg; ?>/5 (<?php echo $nums; ?> Votes)</span>
        </td>
     </tr>
    </table>
     
    <table>
        <tr>
    	<form id="form1" method="post" name="form1" action="">
            <td style="text-align:center;font-size:10px;padding:0px;line-height:10px;vertical-align:middle;" title="1 Terrible">
                1</td>
            <td style="padding: 0px; line-height: 0px; font-size: 0px;">   
     
                <span title="1 Terrible" style="padding: 0px; font-size: 0px;
                    line-height: 0px;"><input id="users" type="radio" name="users" value="1" onclick="showUser(this.value)" tabindex="1" /></span></td>
            <td style="padding: 0px; line-height: 0px; font-size: 0px;">
                <span title="2 Poor" style="padding: 0px; font-size: 0;
                    line-height: 0;"><input id="users" type="radio" name="users" value="2" onclick="showUser(this.value)" tabindex="2" /></span></td>
     
            <td style="padding: 0px; line-height: 0px; font-size: 0px;">
                <span title="3 Average" style="padding: 0px; font-size: 0;
                    line-height: 0;"><input id="users" type="radio" name="users" value="3" onclick="showUser(this.value)" tabindex="3" /></span></td>
            <td style="padding: 0px; line-height: 0px; font-size: 0px;">
                <span title="4 Good" style="padding: 0px; font-size: 0;
                    line-height: 0;"><input id="users" type="radio" name="users" value="4" onclick="showUser(this.value)" tabindex="4" /></span></td>
            <td style="padding: 0px; line-height: 0px; font-size: 0px;">
                <span title="5 Excellent" style="padding: 0px; font-size: 0;
                    line-height: 0;"><input id="users" type="radio" name="users" value="5" onclick="showUser(this.value)" tabindex="5" /></span></td>
          <td style="text-align:center;font-size:10px;padding:0px;line-height:10px;vertical-align:middle;" title="5 Excellent">
                5</td>
           </form>
        </tr>
    </table>
    </div>
    </div>
    </body></html>


    selectbarcrawl.js

    Code JavaScript:
    var xmlHttp
     
    function showUser(str)
    { 
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
    alert ("Browser does not support HTTP Request")
    return
    }        
    var url="selectbarcrawl.php"
    url=url+"?q="+str
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChanged 
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    }
     
    function stateChanged() 
    { 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
       { 
       document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
       } 
    } 
     
    function GetXmlHttpObject()
    {
      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;
    }


    selectbarcrawl.php

    Code PHP:
    <?php 
    include("includes/config.php");
    if($_SESSION['uid']=="")
    {
    header("Location:submit_warning1.php");
    }
    $uid=$_SESSION['uid']; 
    $q=$_GET["q"];
    $qry="insert into m4s_rating set bar_id='$uid',vote='".$q."',rdate='".date('y/m/d')."'";
    mysql_query($qry) or die("Sorry please try this later...");
    $qr1=mysql_query("select id,vote from m4s_rating where bar_id='$uid'");
    $num=mysql_num_rows($qr1);
    $ctr=0;
    while($row=mysql_fetch_array($qr1))
    {
    $ctr=$ctr+$row['vote'];
    }
    $avg=($ctr)/($num);
    $avg=round($avg, 2);
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <script src="js/selectbarcrawl.js"></script>
    </head>
    <body>
     <div id="ctl00_C1_UpdatePanel1">
    <table width='100'>
     <tr>
       <td>
               Overall Rating:<span class="RateBarTxt"><?php echo $avg; ?>/5 (<?php echo $nums; ?> Votes)</span>
        </td>
     </tr>
    </table>
    </div>
    </body></html>

    This script running successfully.
    but now i want
    as link
    http://www.barcrawl.co.uk/pubcrawl.aspx?Crawl=21

    Preloader image display before insert value in database.

  10. #10
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,501
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Can't help you with the preloader image, but this part of your code
    Code PHP:
    $qr1s=mysql_query("select id,vote from m4s_rating where bar_id='$uid'");
    $nums=mysql_num_rows($qr1s);
    $ctr=0;
    while($row=mysql_fetch_array($qr1s))
    {
      $ctr=$ctr+$row['vote'];
    }
    $avg=($ctr)/($nums);
    $avg=round($avg, 2);
    I think can be done almost entirely in the query:
    Code PHP:
    $qr1s = mysql_query("
      SELECT
          SUM(vote) AS ctr
        , COUNT(id) AS nums
      FROM m4s_rating 
      WHERE bar_id = '$uid'
    ");
    $row = mysql_fetch_array($qr1s);
    $avg = round($row['ctr'] / $row['nums'], 2);
    I didn't test it though

  11. #11
    SitePoint Zealot asrasrasr's Avatar
    Join Date
    Apr 2009
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks provided query running fast. thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •