Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <table class="table table-striped">
- <thead>
- <tr>
- <th>#</th>
- <th>Author</th>
- <th>Request</th>
- <th>Rating</th>
- <th>Options</th>
- </tr>
- </thead>
- <tbody>
- <?php
- $servername = "";
- $username = "";
- $password = "";
- $dbname = "";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "SELECT id, name, request, rating, report FROM requests WHERE visible = 1 ORDER BY rating DESC";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- // output data of each row
- while($row = mysqli_fetch_array($result)) {
- if($_POST[rate]){ //they have clicked the submit button
- $error = ''; //truncate the errors
- if($error){ //errors have occurred
- echo 'Sorry. The following error(s) occurred:<br> <br>'.$error.'<br>« <a href="home.php">Back</a>';
- }else{ //no errors
- $id = $_POST['rate'];
- mysql_query("UPDATE requests SET rating = rating + 1 WHERE id = $id");
- }
- }else{ //not clicked the submit button
- echo '
- <form method="post" class="form-inline">
- <tr><td>' . $row["id"]. '</td><td>' . $row["name"]. '</td><td>' . $row["request"]. '</td><td>
- <button type="submit" class="btn btn-success" name="rate" value="' . $row["id"] . '">+ ' . $row["rating"] . '</button></td><td>
- <button type="submit" class="btn btn-primary" name="" value="">Like (0)</button>
- <button type="submit" class="btn btn-primary" name="" value="">Comment (0) </button>
- <button type="submit" class="btn btn-danger" name="" value="">Report</button></td></tr>
- </form>
- ';
- }
- }
- } else {
- echo "There is currently no outstanding requests!";
- }
- $conn->close();
- ?>
- </tbody>
- </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement