Guest User

Untitled

a guest
Jan 20th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.13 KB | None | 0 0
  1. require_once 'includeconfig.php';
  2. // connect to database
  3. $con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
  4. mysqli_set_charset($con, 'utf8');
  5.  
  6. //GETS
  7. if(isset ($_GET['ID']) && isset($_GET['Rating'])){
  8. $ID = $_GET['ID'];
  9. $MyRate = $_GET['Rating']; }
  10. else{return;}
  11.  
  12.  
  13. //CountVote
  14. $sql1="UPDATE `civilarticle` SET `Counter`= `Counter`+1 WHERE `ID`=$ID";
  15. $sql2= "SELECT `Counter` FROM `civilarticle` WHERE `ID`=$ID";
  16. if($con->query($sql1) === TRUE ){
  17. //echo "Item updated successfully"."<br>";
  18. } else{
  19. echo "Error : " . $con->error ;
  20. }
  21. if ($result = $con->query($sql2)) {
  22. /* fetch associative array */
  23. while ($row = $result->fetch_assoc()) {
  24. $COUNTVote=$row["Counter"];
  25. //echo "<br>".$row["Counter"]."<br>"."*****"."<br>";
  26. }}
  27.  
  28.  
  29. //PASTVote
  30. if(`Counter`<1){
  31. $sql3="UPDATE `civilarticle` SET `PastRate`= (`PastRate`+$MyRate)/2 WHERE `ID`=$ID";}
  32. else{$sql3="UPDATE `civilarticle` SET `PastRate`= 0 WHERE `ID`=$ID";}
  33. $sql4= "SELECT `PastRate` FROM `civilarticle` WHERE `ID`=$ID";
  34. if($con->query($sql3) === TRUE ){
  35. //echo "Item updated successfully"."<br>";
  36. } else{
  37. echo "Error : " . $con->error ;
  38. }
  39. if ($result = $con->query($sql4)) {
  40. /* fetch associative array */
  41. while ($row = $result->fetch_assoc()) {
  42. $PASTVote=$row["PastRate"];
  43. //echo "<br>".$row["PastRate"]."<br>"."*****"."<br>";
  44. }}
  45.  
  46. //YOURVote
  47. $sql5 = "UPDATE `civilarticle` SET `YourRate`='$MyRate' WHERE `ID`=$ID";
  48. $sql6="SELECT `YourRate` FROM `civilarticle` WHERE `ID`=$ID";
  49. if($con->query($sql5) === TRUE){
  50. //echo "Item updated successfully"."<br>";
  51. } else{
  52. echo "Error : " . $con->error ;
  53. }
  54. if ($result = $con->query($sql6)) {
  55. /* fetch associative array */
  56. while ($row = $result->fetch_assoc()) {
  57. $YOURVote=$row["YourRate"];
  58. //echo "<br>".$YOURVote['YourRate']."<br>"."*****"."<br>";
  59. }}
  60.  
  61. //AVVote
  62. if(`Counter`<1 ){
  63. $sql7="UPDATE `civilarticle` SET `Rating`=($MyRate + (`Counter`-1)*`PastRate`)/`Counter` WHERE ID=$ID";}
  64. else{$sql7="UPDATE `civilarticle` SET `Rating`= $MyRate WHERE `ID`=$ID";}
  65. $sql8= "SELECT `Rating` FROM `civilarticle` WHERE `ID`=$ID";
  66.  
  67. if($con->query($sql7) === TRUE){
  68. //echo "Item inserted successfully"."<br>";
  69. } else{
  70. echo "Error : " . $con->error ;
  71. }
  72. if ($result = $con->query($sql8)) {
  73. /* fetch associative array */
  74. while ($row = $result->fetch_assoc()) {
  75. $AVVote=$row["Rating"];
  76. //echo "<br>".$row["Rating"]."<br>"."*****"."<br>";
  77. }}
  78.  
  79. $arr=array("OldRate"=>$PASTVote,"YourRate"=>$YOURVote,"TotalRate"=>$AVVote,"CountVote"=>$COUNTVote);
  80. echo json_encode($arr);
  81.  
  82. public class DetailActivity extends Activity {
  83.  
  84. //
  85. private static final String TAG =DetailActivity.class.getSimpleName();
  86. TextView txtMain,txtTiltle;
  87. ImageView imgView;
  88. //
  89. String title;
  90.  
  91. ///
  92. int ID=2; //put extra give me this value
  93. public float Rate;
  94. Button btn_submit,btn_detail;
  95. RatingBar ratingbar;
  96.  
  97. //get ?"+"ID="+ID+"&"+"Rating="+Rate
  98. String url= "http://192.168.1.103/android_login_api/rating.php?"+"ID="+ID+"&"+"Rating="+Rate;
  99. TextView pastrate,yourrate,totalrate;
  100.  
  101. @Override
  102. protected void onCreate(Bundle savedInstanceState) {
  103. super.onCreate(savedInstanceState);
  104. setContentView(R.layout.activity_detail);
  105.  
  106. txtTiltle = (TextView) findViewById(R.id.txtTitle);
  107. txtMain = (TextView) findViewById(R.id.txtMain);
  108. imgView = (ImageView) findViewById(R.id.imgView);
  109.  
  110.  
  111. ///
  112. btn_detail= (Button) findViewById(R.id.button2);
  113. pastrate= (TextView) findViewById(R.id.t1);
  114. yourrate=(TextView) findViewById(R.id.t2);
  115. totalrate=(TextView) findViewById(R.id.t3);
  116. ////
  117.  
  118. Bundle extras = getIntent().getExtras();
  119. if (extras!=null){
  120. if(extras.containsKey("Title")){
  121. title = extras.getString("Title");
  122. txtTiltle.setText(title);
  123. }
  124. }
  125.  
  126. ///my code for rating
  127. btn_submit= (Button) findViewById(R.id.button);
  128. ratingbar = (RatingBar) findViewById(R.id.ratingBar);
  129.  
  130. btn_submit.setOnClickListener(new View.OnClickListener(){
  131.  
  132. @Override
  133. public void onClick(View v) {
  134. Rate = ratingbar.getRating();
  135. // Toast.makeText(DetailActivity.this,""+ratingbar.getRating(),Toast.LENGTH_SHORT).show();
  136. if(Rate!=-1){
  137. btn_submit.setEnabled(false);
  138.  
  139.  
  140. }
  141.  
  142.  
  143. }
  144.  
  145. });
  146.  
  147.  
  148.  
  149. btn_detail.setOnClickListener(new View.OnClickListener() {
  150. @Override
  151. public void onClick(View v) {
  152. Toast.makeText(DetailActivity.this,url,Toast.LENGTH_SHORT).show();
  153.  
  154. CustomRequest CustomRequest = new CustomRequest(Request.Method.GET, url, null,
  155. new Response.Listener<JSONObject>() {
  156. @Override
  157. public void onResponse(JSONObject response) {
  158.  
  159. try {
  160. pastrate.setText(response.getString("OldRate"));
  161. yourrate.setText(response.getString("YourRate"));
  162. totalrate.setText( response.getString("TotalRate"));
  163. } catch (JSONException e) {
  164. e.printStackTrace();
  165. }
  166. Toast.makeText(DetailActivity.this,response+"",Toast.LENGTH_SHORT).show();
  167. }
  168. }, new Response.ErrorListener() {
  169.  
  170. @Override
  171. public void onErrorResponse(VolleyError volleyError) {
  172. Log.e("ERROR", "Error occurred ", volleyError);
  173. //Toast.makeText(DetailActivity.this,"Failed",Toast.LENGTH_SHORT).show();
  174. volleyError.printStackTrace();
  175. }
  176. }) {
  177. @Override
  178. protected Map<String, String> getParams() {
  179. Map<String, String> params = new HashMap<String, String>();
  180. params.put("ID", );
  181. params.put("Rating",);
  182. return params;
  183. }
  184. };
  185. Toast.makeText(DetailActivity.this, valueOf(Rate),Toast.LENGTH_SHORT).show();
  186.  
  187. AppController.getInstance().addToRequestQueue(CustomRequest);
  188. }
  189. });
  190.  
  191.  
  192. }
  193.  
  194. }
Add Comment
Please, Sign In to add comment