I need help converting a MySQL object to a string

Problems with the Windows version of XAMPP, questions, comments, and anything related.

I need help converting a MySQL object to a string

Postby Chiriel » 05. July 2016 02:48

XAMPP version is 7.0.4
Installation file type Application (exe)
Full name is xampp-win32-7.0.4-0-VC14-installer

My Operating System is Windows 10
64 bit Operating System/x64 processor
Home Edition
*Not sure where to find the service pack level

The installation path is C:\xampp\new_directory

I'm currently trying to make a navigation menu from one of my columns in my mysql table.

Okay, so in my PHP class Database file, I have this function:

public function get_food_type(){
return $this->query("SELECT food_type FROM menu");

And in the other file I have the following code:



$content = "<div id=\"menu\">"
. "<nav id=\"food\">"
. "<ul>"

. $type=wzDB::getInstance()->get_food_type();
while($row = $type->fetch_assoc()){
echo "<li>" . htmlspecialchars($row['food_type']) . "</li>";

. "</nav>"
. "</div>";

But when I try to run the file, I get the following error message

Catchable fatal error: Object of class mysqli_result could not be converted to string in C:\xampp\new_directory\htdocs\Wu_Zen2\menu.php on line 8

How do I fix this error?
Posts: 18
Joined: 15. April 2016 18:03
XAMPP version: 3.2.2
Operating System: Wndows 10

Re: I need help converting a MySQL object to a string

Postby Nobbie » 05. July 2016 13:39

This is horrible Code, remove the concatenation in front of the line "$type=wzDB::getInstance()->get_food_type()" and insert a semicolon instead in the end of the line before. What did you think when you coded that??


Code: Select all
$content = "<div id=\"menu\">"
. "<nav id=\"food\">"
. "<ul>"
. $type=wzDB::getInstance()->get_food_type();

vs. Correct:

Code: Select all
$content = "<div id=\"menu\">"
. "<nav id=\"food\">"
. "<ul>";

But I think you will receive some more errors, as the lonesome HTML strings in the bottom of the file are also totally wrong. That is not valid PHP syntax.

You should get some basic tutorials about PHP and read them carefully and work out some examples. That code is a pain.
Posts: 9064
Joined: 09. March 2008 13:04

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 64 guests