0

I'm having problems with the Array to string conversion error. It's occurring here:

 <div id="pagename">
       <?php echo ['SELECT name FROM hjemmesider']; ?>  
   </div> 

I'm trying to fetch a row from my db and display it, but i can't make it work... I have tried tons of things to try and sort it out, and of course researched it a great bit on the internet.

Rick
  • 3,240
  • 2
  • 29
  • 53
  • You need to add far more detail to your question! Do you have some example data from your db? Examples of what you've tried? – scottevans93 Jul 19 '16 at 13:09
  • 1
    This is PHP/MySQL 101 and there are [thousands of tutorials online](https://www.google.com/search?q=how+to+get+data+from+mysql+in+php). – Jay Blanchard Jul 19 '16 at 13:11

2 Answers2

-1

in your foreach or while use echo $row['your_field_name'];

You are not doin it right.. try like this:

$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
    }
} else {
    echo "0 results";
}
Adrian
  • 171
  • 1
  • 6
-2

It most probably means that you are trying to echo an Array. Use print_r function on your result and things will get clearer.

Tiberiu Petcu
  • 822
  • 7
  • 10