2

I want to display 30 rows from an data base,on an TABLE, but just the approved entries. This "approved entries" are defined for an row with values "1 for approved" and "0 for NOT approved"

This is the code wath I need to change:

<?php
$servername = "localhost";
$username = "username ";
$password = "password";
$dbname = "name";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT id, label, title_id, season, episode, approved FROM links order by id desc LIMIT 30 OFFSET 1";
$result = $last_id = $conn->query($sql);


if ($result->num_rows > 0)
 {
    echo "<table><tr><th>ID</th><th>Audio</th><th>URL</th><th>Temporada</th><th>Episodio</th><th>Aprobado</th></tr>";
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "<tr><td>".$row["id"]."</td><td>".$row["label"]."</td>";
        echo "<td><a href=";
        if (empty($row['episode'])) {
     echo '/peliculas-online/'.$row["title_id"];
    }
    else {
     echo '/series-online/'.$row['title_id'].'/seasons/'.$row['season'].'/episodes/'.$row["episode"];
        }
        echo ">".$row["title_id"]."</a></td>";
        echo "<td>".$row["season"]."</td><td>".$row["episode"]."</td><td>".$row["approved"]."</td></tr>";
    }
    echo "</table>";
} else {
    echo "0 results";
}
$conn->close();
?>

Like you can see, this code list all (approved or not)... how to get something like this:

if row approved=1 display rows, else hide (hide all not just the approved row)

Need to HIDE all entries from this table row if entry is not approved -> id-label-title_id-season-episode-approved

Thanks

1
  • so what exactly is the problem? you've already got the necessary pseudo-code... Commented Jun 29, 2015 at 18:29

1 Answer 1

1

You should know about the MySQL WHERE clause in SELECT.

Something like:

"SELECT id, label, title_id, season, episode, approved 
 FROM links 
 WHERE approved = 1 
 ORDER BY id desc 
 LIMIT 30 OFFSET 1";

Reference:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.