-5

I'm trying to retrieve information from a MYSQL DB. However, I get this error.

My code:

$result = mysql_query("SELECT * FROM DB ORDER BY name ASC");
while($row = mysql_fetch_array($result)) {
   echo  ucwords($row['name']) . "\t" . ucwords($row['number']) . "<br>"; 
   echo "<hr width='20%'>";
}
kero
  • 10,557
  • 5
  • 40
  • 49

2 Answers2

1

You have an error in your query. So mysql_query is not giving you a resultset. Instead you get the value false, thus a boolean.

N0lf
  • 148
  • 7
0

Use http://www.php.net/manual/en/book.pdo.php instead of mysql function!

Example #1 Demonstrate PDO::query

<?php
function getFruit($conn) {
    $sql = 'SELECT name, color, calories FROM fruit ORDER BY name';
    foreach ($conn->query($sql) as $row) {
        print $row['name'] . "\t";
        print $row['color'] . "\t";
        print $row['calories'] . "\n";
    }
}
?>
Eugen
  • 1,328
  • 12
  • 15