0

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];
}
3
  • 1
    try SELECT * FROM resources . resources Commented Jul 16, 2014 at 22:40
  • also, mysql is deprecated, no longer supported and may be insecure. You should use mysqli or PDO. Commented Jul 16, 2014 at 22:41
  • Hmmm i tried out your suggestions and still no luck. It loads my footer and title but still no content... :( Commented Jul 16, 2014 at 22:44

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. That was very helpful. I didnt know that i didnt need that extra parameter. Once i moved it to "mysql_select_db" it started working. Thank you so much!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.