xgd Posted July 29, 2009 Share Posted July 29, 2009 Hello, I am getting the following error when i try to run some script: Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given The script is a bit longish, so here's the part that matters (hopefully): case "content": #110 $dept_id = $_GET['dept_id']; $type_id = $_GET['type_id']; $sql = "SELECT a.name, a.type_id, b.title, b.description, b.content_date, b.create_date, b.created_by, b.last_upd_date, b.last_upd_by, c.name as dept_name, content_id FROM Content_Type a, Department c LEFT OUTER JOIN Content b on a.type_id = b.content_type and a.type_id = b.content_type and b.dept_id = $dept_id and b.content_type = $type_id WHERE c.dept_id = $dept_id ORDER BY content_date DESC"; $results = mysqli_query($cxn, $sql); $body_links = ""; $content_count = 0; $page["body_text"] = ""; while($row = mysqli_fetch_assoc($results)) #132 { if (!isset($area_name) && $type_id == $row["type_id"]) { I think it's something to do with the joints, and i personally don't know a thing about them (if that's the problem). I am usng Mysql version 5 something. thanks Quote Link to comment https://forums.phpfreaks.com/topic/167952-mysqli-error/ Share on other sites More sharing options...
patrickmvi Posted July 29, 2009 Share Posted July 29, 2009 That error indicates that your query is failing. You should do a mysqli_error($cxn) right after your mysqli_query call to see what the error is. It may be the way that you're mixing the different types of joins but I won't know for sure until I see that actual MySQL error. Quote Link to comment https://forums.phpfreaks.com/topic/167952-mysqli-error/#findComment-885831 Share on other sites More sharing options...
Adam Posted July 29, 2009 Share Posted July 29, 2009 I think you have the $sql and $cxn variables in the wrong order in your mysqli_query() call. Edit: No you don't! Thought it was same syntax as mysql_query(). Quote Link to comment https://forums.phpfreaks.com/topic/167952-mysqli-error/#findComment-885832 Share on other sites More sharing options...
Adam Posted July 29, 2009 Share Posted July 29, 2009 Ah, you need to make sure the returned result variable ($results) is not equal to false to prevent the error in future. As patrick mentioned, use the mysqli_error() function to find out why the query's failing. Quote Link to comment https://forums.phpfreaks.com/topic/167952-mysqli-error/#findComment-885835 Share on other sites More sharing options...
xgd Posted July 29, 2009 Author Share Posted July 29, 2009 hello, I get this: Unknown column 'a.type_id' in 'on clause' Quote Link to comment https://forums.phpfreaks.com/topic/167952-mysqli-error/#findComment-885879 Share on other sites More sharing options...
Dathremar Posted July 29, 2009 Share Posted July 29, 2009 Make sure the table "Content_Type" has a column named type_id Quote Link to comment https://forums.phpfreaks.com/topic/167952-mysqli-error/#findComment-885883 Share on other sites More sharing options...
xgd Posted July 29, 2009 Author Share Posted July 29, 2009 The mysql syntax is for mysqli 4.0 or 4.1 i think, that's what the book uses, so it needs some modification for mysql 5 i believe. p.s. it does have type_id Quote Link to comment https://forums.phpfreaks.com/topic/167952-mysqli-error/#findComment-885890 Share on other sites More sharing options...
Dathremar Posted July 29, 2009 Share Posted July 29, 2009 ELECT a.name, a.type_id, b.title, b.description, b.content_date, b.create_date, b.created_by, b.last_upd_date, b.last_upd_by, c.name as dept_name, content_id FROM (Content_Type a, Department c) LEFT OUTER JOIN Content b on a.type_id = b.content_type and a.type_id = b.content_type and b.dept_id = $dept_id and b.content_type = $type_id WHERE c.dept_id = $dept_id ORDER BY content_date DESC True. You need to put the table names in "( table name1 as a, table_name2 as b) LEFT JOIN ....." when you use join's. Quote Link to comment https://forums.phpfreaks.com/topic/167952-mysqli-error/#findComment-885893 Share on other sites More sharing options...
xgd Posted July 29, 2009 Author Share Posted July 29, 2009 thanks dathremar, that helped, though there are still issues with the app, but i think it's too complicated to discuss here. Quote Link to comment https://forums.phpfreaks.com/topic/167952-mysqli-error/#findComment-885920 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.