0

can help me? I've a site url like:

http://www.example.com/episodio/ID

ID = row number from Database.

I want to display the page title.

I've this:

.htaccess file:

RewriteEngine on
RewriteRule ^episodio/(\w+)/?$ episodio.php?id=$1

php file:

$sql = "SELECT * FROM "episodios" WHERE serie = ".$id." AND temporada = ".$i." ORDER BY "episodio" ASC";
            $result = $conn->query($sql);
                if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                    if ($row['episodio'] == 0) {
                        echo '<a href="episodio/'.$row["id"].'"><li><strong>Episodio doble:</strong> '.$row["nombre"].'<img src="http://www.example.net/img/play.png" class="img-play"></li></a>';
                    }else{
                        echo '<a href="episodio/'.$row["id"].'"><li><strong>Episodio '.$row['episodio'].':</strong> '.$row["nombre"].'<img src="http://www.example.net/img/play.png" class="img-play"></li></a>';
                    }
            ?>
            <?php } ?>
0

2 Answers 2

1

You're using $_GET in your ID anywhere before this code?

I mean, $_GET['id'].

Most PHP versions (since 4...) doesn't catch the var just for its name.

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

5 Comments

I must get the id first?
Yep. Your problem may be on WHERE serie = ".$id.", probably the var wasn't stored.
Another thing, be careful using variables right into your sql. As you seems to be using MySQLi, might want to use prepare first.
"Some PHP versions"? Is there any PHP version that does?
Yes. PHP 4 had some versions that accepted this... Sure, nobody uses it anymore, just had to be sure :P
0

I'd recommend getting all your variables from the DB first, and then printing out the HTML (perhaps from a template file). We assume that $row contains more than just an ID? Perhaps an "título del episodio", also?

if ($result->num_rows > 0) {
    $episodios = array();
    $x = 0;
    while($row = $result->fetch_assoc()) {
        $episodios[$x]['id'] = $row['id'];
        if ($x == 0) {
            $PageTitle = $row['title'];
        }
        $x++;
    }

Then your template can use $PageTitle (from the first episode), and you can loop through the $episodios array to construct the links for the other episodes.

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.