
In the left menu I'm going to have the top 10 most viewed guides left aligned and with a hyperlink to the page (which hasn't been attempted in the code I will show you. I'm trying to get it to display first). Right aligned to the right of it (in another td or div) I will display the amount of views. Right now just to display what I want it to look like It's just using <ul><li> tags. Now my book is telling me to go by this script that I followed as close as possible (but made changes to adapt to my needs).
Code: Select all
<?php
$host = 'localhost';
$user = 'groog_admin';
$pass = 'password';
$query = "SELECT guide_name AS name, guide_views AS views FROM guides_table ORDER BY guide_views ASC LIMIT 10";
$connect = @mysql_connect($host, $user, $pass) or die('Error connecting to MySQL!');
@mysql_select_db(groog_guides) or die('Error connecting to database!');
$result = @mysql_query($query);
if ($result){
echo '<tr><td align="left">Name</td><td align="right">Views</td></tr>";
while ($row = $mysql_fetch_array($result, MYSQL_ASSOC))
{
echo '<tr><td align="left">' . $row['name'] . '</td><td align="right">' . $row['views'] . '</td></tr>';
}
mysql_free_result($result);
mysql_end();
?>
So I think It's safe to say that the problem is this last chunk of code-
Code: Select all
if ($result){
echo '<tr><td align="left">Name</td><td align="right">Views</td></tr>";
while ($row = $mysql_fetch_array($result, MYSQL_ASSOC))
{
echo '<tr><td align="left">' . $row['name'] . '</td><td align="right">' . $row['views'] . '</td></tr>';
}
Don't worry about that chunk of text that is now in the left menu. That's just the forced ad that sits at the bottom (that I shrunk down). But everything from there over disappeared (because that come relatively first in the index.php file). So my question is, How can I retrieve data and display it? Why won't my code work?
Thanks in advanced