Advertisement
Guest User

Untitled

a guest
Jan 12th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. <table class="table table-striped">
  2. <thead>
  3. <tr>
  4. <th>#</th>
  5. <th>Author</th>
  6. <th>Request</th>
  7. <th>Rating</th>
  8. <th>Options</th>
  9. </tr>
  10. </thead>
  11. <tbody>
  12.  
  13. <?php
  14. $servername = "";
  15. $username = "";
  16. $password = "";
  17. $dbname = "";
  18.  
  19. // Create connection
  20. $conn = new mysqli($servername, $username, $password, $dbname);
  21. // Check connection
  22. if ($conn->connect_error) {
  23. die("Connection failed: " . $conn->connect_error);
  24. }
  25.  
  26. $sql = "SELECT id, name, request, rating, report FROM requests WHERE visible = 1 ORDER BY rating DESC";
  27. $result = $conn->query($sql);
  28.  
  29. if ($result->num_rows > 0) {
  30. // output data of each row
  31. while($row = mysqli_fetch_array($result)) {
  32.  
  33. if($_POST[rate]){ //they have clicked the submit button
  34. $error = ''; //truncate the errors
  35. if($error){ //errors have occurred
  36. echo 'Sorry. The following error(s) occurred:<br> <br>'.$error.'<br>&laquo; <a href="home.php">Back</a>';
  37. }else{ //no errors
  38. $id = $_POST['rate'];
  39. mysql_query("UPDATE requests SET rating = rating + 1 WHERE id = $id");
  40. }
  41. }else{ //not clicked the submit button
  42. echo '
  43.  
  44. <form method="post" class="form-inline">
  45.  
  46. <tr><td>' . $row["id"]. '</td><td>' . $row["name"]. '</td><td>' . $row["request"]. '</td><td>
  47.  
  48. <button type="submit" class="btn btn-success" name="rate" value="' . $row["id"] . '">+ ' . $row["rating"] . '</button></td><td>
  49.  
  50. <button type="submit" class="btn btn-primary" name="" value="">Like (0)</button>
  51. <button type="submit" class="btn btn-primary" name="" value="">Comment (0) </button>
  52. <button type="submit" class="btn btn-danger" name="" value="">Report</button></td></tr>
  53. </form>
  54.  
  55. ';
  56. }
  57.  
  58.  
  59. }
  60. } else {
  61. echo "There is currently no outstanding requests!";
  62. }
  63. $conn->close();
  64. ?>
  65. </tbody>
  66. </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement