Problems Outputting PHP from MySQL

I am trying to import MySQL data into PHP through the WordPress PHP Snippet plugin. For whatever reason I keep getting error ‘mysql_fetch_array() expects parameter 1 to be resource, boolean’.

My code is as follows:

Read More

Connection

[insert_php]
$conn = mysql_connect("localhost", "albert", "notrealpassword") or die     
(mysql_error());

PHP

mysql_select_db('mydatabase');    
$query = "SELECT * FROM mytable";
$result = mysql_query($query);
while ($subjectone = mysql_fetch_array($result))
{echo $subjectone['dataintable'];}
[/insert_php]

Related posts

Leave a Reply

1 comment

  1. It is because before the last result the answer of mysql_fetch_array is array but while waits for bolean.
    Also probably you know it is better to use new MySQLi functions

    mysql_select_db('mydatabase');    
    $query = "SELECT * FROM mytable";
    $result = mysql_query($query);
    while (is_array($subjectone = mysql_fetch_array($result)))
    {echo $subjectone['dataintable'];}