0

Currently I'm creating just a simple website that I'm fooling around with. Users can add movies to watch, and then can view them later on. What my current problem is, is this.

enter image description here

Sorry for the large image. As you can see its displaying the first result correctly, but the second result gets all skrewy and displays at the top of the screen. My code for displaying the data is:

$result = mysql_query("SELECT * FROM `movies`");

echo "
<table id=\"allTable\" align=\"center\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" width=\"100%\">
<tr>
<th>ID</th>
<th>Movie</th>
<th>Genre</th></tr>";

while($row = mysql_fetch_array($result)){
    echo "<tr>";
    echo "<td>" . $row['id'] . "</td>";
    echo "<td>" . $row['name'] . "</td>";
    echo "<td>" . $row['genre'] . "</td";
    echo "</tr><br />";
    echo "</table>";
}

Any help would be greatly appreciated!

EDIT Fixed the problem right after I created this. Removed from while loop and put it under. Fixed.

1 Answer 1

1

echo "</table>"; should be moved outside of your while($row = mysql_fetch_array($result))

while($row = mysql_fetch_array($result)){
                echo "<tr>";
                echo "<td>" . $row['id'] . "</td>";
                echo "<td>" . $row['name'] . "</td>";
                echo "<td>" . $row['genre'] . "</td";
                echo "</tr><br />";

            }
echo "</table>";
Sign up to request clarification or add additional context in comments.

1 Comment

True... Although you should consider looking at php.net/manual/en/book.pdo.php

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.