Skip to content
Advertisement

MySQLi Select to PHP variable

I wrote a PHP script with a database connection, which appears to work properly. The problem I’m having is in using a SELECT statement to fetch values from my database and assign those values to PHP variables.

This is my table:
my table

If I copy the SQL into PHPMyAdmin, I get the right result, so I trust the query itself.

I get an error, if I write:

JavaScript

What do I do wrong?

This is my full code:

JavaScript

Advertisement

Answer

You need to fetch the results.

JavaScript

http://php.net/manual/en/mysqli-result.fetch-assoc.php

Aside from fetching the results you should redesign the table. You shouldn’t have more than one value per ‘table cell’. For instance you have comma separated values for the size/color etc of the product. You should have those as separate attributes in the table or maybe even a separate table.

Example:

enter image description here

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement