Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require_once 'includeconfig.php';
- // connect to database
- $con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
- mysqli_set_charset($con, 'utf8');
- //GETS
- if(isset ($_GET['ID']) && isset($_GET['Rating'])){
- $ID = $_GET['ID'];
- $MyRate = $_GET['Rating']; }
- else{return;}
- //CountVote
- $sql1="UPDATE `civilarticle` SET `Counter`= `Counter`+1 WHERE `ID`=$ID";
- $sql2= "SELECT `Counter` FROM `civilarticle` WHERE `ID`=$ID";
- if($con->query($sql1) === TRUE ){
- //echo "Item updated successfully"."<br>";
- } else{
- echo "Error : " . $con->error ;
- }
- if ($result = $con->query($sql2)) {
- /* fetch associative array */
- while ($row = $result->fetch_assoc()) {
- $COUNTVote=$row["Counter"];
- //echo "<br>".$row["Counter"]."<br>"."*****"."<br>";
- }}
- //PASTVote
- if(`Counter`<1){
- $sql3="UPDATE `civilarticle` SET `PastRate`= (`PastRate`+$MyRate)/2 WHERE `ID`=$ID";}
- else{$sql3="UPDATE `civilarticle` SET `PastRate`= 0 WHERE `ID`=$ID";}
- $sql4= "SELECT `PastRate` FROM `civilarticle` WHERE `ID`=$ID";
- if($con->query($sql3) === TRUE ){
- //echo "Item updated successfully"."<br>";
- } else{
- echo "Error : " . $con->error ;
- }
- if ($result = $con->query($sql4)) {
- /* fetch associative array */
- while ($row = $result->fetch_assoc()) {
- $PASTVote=$row["PastRate"];
- //echo "<br>".$row["PastRate"]."<br>"."*****"."<br>";
- }}
- //YOURVote
- $sql5 = "UPDATE `civilarticle` SET `YourRate`='$MyRate' WHERE `ID`=$ID";
- $sql6="SELECT `YourRate` FROM `civilarticle` WHERE `ID`=$ID";
- if($con->query($sql5) === TRUE){
- //echo "Item updated successfully"."<br>";
- } else{
- echo "Error : " . $con->error ;
- }
- if ($result = $con->query($sql6)) {
- /* fetch associative array */
- while ($row = $result->fetch_assoc()) {
- $YOURVote=$row["YourRate"];
- //echo "<br>".$YOURVote['YourRate']."<br>"."*****"."<br>";
- }}
- //AVVote
- if(`Counter`<1 ){
- $sql7="UPDATE `civilarticle` SET `Rating`=($MyRate + (`Counter`-1)*`PastRate`)/`Counter` WHERE ID=$ID";}
- else{$sql7="UPDATE `civilarticle` SET `Rating`= $MyRate WHERE `ID`=$ID";}
- $sql8= "SELECT `Rating` FROM `civilarticle` WHERE `ID`=$ID";
- if($con->query($sql7) === TRUE){
- //echo "Item inserted successfully"."<br>";
- } else{
- echo "Error : " . $con->error ;
- }
- if ($result = $con->query($sql8)) {
- /* fetch associative array */
- while ($row = $result->fetch_assoc()) {
- $AVVote=$row["Rating"];
- //echo "<br>".$row["Rating"]."<br>"."*****"."<br>";
- }}
- $arr=array("OldRate"=>$PASTVote,"YourRate"=>$YOURVote,"TotalRate"=>$AVVote,"CountVote"=>$COUNTVote);
- echo json_encode($arr);
- public class DetailActivity extends Activity {
- //
- private static final String TAG =DetailActivity.class.getSimpleName();
- TextView txtMain,txtTiltle;
- ImageView imgView;
- //
- String title;
- ///
- int ID=2; //put extra give me this value
- public float Rate;
- Button btn_submit,btn_detail;
- RatingBar ratingbar;
- //get ?"+"ID="+ID+"&"+"Rating="+Rate
- String url= "http://192.168.1.103/android_login_api/rating.php?"+"ID="+ID+"&"+"Rating="+Rate;
- TextView pastrate,yourrate,totalrate;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_detail);
- txtTiltle = (TextView) findViewById(R.id.txtTitle);
- txtMain = (TextView) findViewById(R.id.txtMain);
- imgView = (ImageView) findViewById(R.id.imgView);
- ///
- btn_detail= (Button) findViewById(R.id.button2);
- pastrate= (TextView) findViewById(R.id.t1);
- yourrate=(TextView) findViewById(R.id.t2);
- totalrate=(TextView) findViewById(R.id.t3);
- ////
- Bundle extras = getIntent().getExtras();
- if (extras!=null){
- if(extras.containsKey("Title")){
- title = extras.getString("Title");
- txtTiltle.setText(title);
- }
- }
- ///my code for rating
- btn_submit= (Button) findViewById(R.id.button);
- ratingbar = (RatingBar) findViewById(R.id.ratingBar);
- btn_submit.setOnClickListener(new View.OnClickListener(){
- @Override
- public void onClick(View v) {
- Rate = ratingbar.getRating();
- // Toast.makeText(DetailActivity.this,""+ratingbar.getRating(),Toast.LENGTH_SHORT).show();
- if(Rate!=-1){
- btn_submit.setEnabled(false);
- }
- }
- });
- btn_detail.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Toast.makeText(DetailActivity.this,url,Toast.LENGTH_SHORT).show();
- CustomRequest CustomRequest = new CustomRequest(Request.Method.GET, url, null,
- new Response.Listener<JSONObject>() {
- @Override
- public void onResponse(JSONObject response) {
- try {
- pastrate.setText(response.getString("OldRate"));
- yourrate.setText(response.getString("YourRate"));
- totalrate.setText( response.getString("TotalRate"));
- } catch (JSONException e) {
- e.printStackTrace();
- }
- Toast.makeText(DetailActivity.this,response+"",Toast.LENGTH_SHORT).show();
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError volleyError) {
- Log.e("ERROR", "Error occurred ", volleyError);
- //Toast.makeText(DetailActivity.this,"Failed",Toast.LENGTH_SHORT).show();
- volleyError.printStackTrace();
- }
- }) {
- @Override
- protected Map<String, String> getParams() {
- Map<String, String> params = new HashMap<String, String>();
- params.put("ID", );
- params.put("Rating",);
- return params;
- }
- };
- Toast.makeText(DetailActivity.this, valueOf(Rate),Toast.LENGTH_SHORT).show();
- AppController.getInstance().addToRequestQueue(CustomRequest);
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment