i want to display category from database, but theres an error. please help
<?php
$kat = mysql_query("SELECT category, category.id from category join product on product.id_category=category.id group by category");
while($list=mysql_fetch_array($kat)){
echo"<li><a href='?v=produk&cat=$list[id]'>$list[category]</a></li>";
}
?>
All my_sql_ functions such as mysql_query() and mysql_fetch_array() were deprecated several years ago and are now removed from the current version of PHP.
Instead of trying to fix this error, you should switch to using my_sqli_ functions or PDO.
@WebMachine is correct, however if you have a pressing need to fix what you have, I suspect the issue is that your query is returning a false result, as the documentation states that a select will either return a results object, or false on error. Is the ‘join’ syntax correct?
You should be checking to see whether the query has executed before you use the results from it, even when you’ve switched to mysqli or PDO. Does the query run without errors from phpMyAdmin?
Having a field name in a table of the same exact name looks like a poor design decision.
IMHO if possible an ALTER TABLE changing the field name to “category_name” or simply “name” (if that is in fact what it is) would help make things clearer for both human and machine.