We help IT Professionals succeed at work.
Get Started

Mysqli join query problems

kgp43
kgp43 asked
on
370 Views
Last Modified: 2015-08-12
Hi,

I have a problem with this query.
What I want is to get the Category Name based on Category ID, each in different tables.

This is what I made so far, but it does not work:

<?php
# Output last 5 used categories
$sql = "SELECT
	inquiries.category, categories.name, categories.id
FROM
	inquiries, categories
WHERE
	userid='$userid'
JOIN
	category
ON
	inquiries.category = categories.id
ORDER BY
	inquiries.createdate
DESC LIMIT 5";
								
$res = $mysqli->query($sql);

while($cat = $res->fetch_array()) {
								
	echo '<option value="'.$cat['categories.id'].'">'.$cat['categories.name'].'</option>';
								
}
?>

Open in new window


Error:
<b>Fatal error</b>:  Call to a member function fetch_array() on a non-object in <b>/home/d/i/ftp_dinethdk/m/inquiry.php</b> on line <b>196</b><br />

Open in new window

Comment
Watch Question
EE Topic Advisor
CERTIFIED EXPERT
Most Valuable Expert 2014
Awarded 2013
Commented:
This problem has been solved!
Unlock 1 Answer and 15 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE