Nick Balistreri
Nick Balistreri

Reputation: 131

Retrieving data from database and displaying on web page not working

I have a database called resources and a table inside that database called resources. I am trying to display some content and having some trouble. This is the code I am using:

mysql_connect('localhost', 'username', 'password', 'resources');
$query   = mysql_query('SELECT * FROM resources WHERE iss = 1 ORDER BY added DESC');
$company = 'company';
while ($rows = mysql_fetch_assoc($query)) {
    echo "Company: " . $rows[$company];
}

Upvotes: 0

Views: 53

Answers (1)

ihgann
ihgann

Reputation: 505

A few things:

  1. You need to properly open that div tag.
  2. You need to select a database using mysql_select_db, not by adding the fourth parameter to mysql_connect.

This all also assumes your connections are working properly and everything is installed fine. Then, you should be able to get it working with something closer to this:

<div id="section_content">
<?php
    mysql_connect('localhost', 'username', 'password');
    mysql_select_db('resources');
    $query = mysql_query('SELECT * FROM resources WHERE iss = 1 ORDER BY added DESC');
    $company = 'company';
    while($rows = mysql_fetch_assoc($query)){
        echo "Company: " .$rows[$company];
    }
?>
</div>

Upvotes: 2

Related Questions