gmc1103 Posted April 28, 2015 Share Posted April 28, 2015 Hi I have this query SELECT COALESCE(id_tempo, 0) AS id_tempos ,`semana_dias`.`dia` , `req_material_sala`.`sala` , `req_material_tempo`.`inicio` FROM sala_ocupacao INNER JOIN `semana_dias` ON (`sala_ocupacao`.`id_dia` = `semana_dias`.`id_dia`) INNER JOIN `req_material_sala` ON (`sala_ocupacao`.`id_sala` = `req_material_sala`.`idsala`) INNER JOIN `req_material_tempo` ON (`sala_ocupacao`.`id_tempo` = req_material_tempo.`idtempo`) ORDER BY id_ocup; That one returns only the values where there is no null If i remove those lines , `req_material_tempo`.`inicio` INNER JOIN `req_material_tempo` ON (`sala_ocupacao`.`id_tempo` = req_material_tempo.`idtempo`) I have the null values converted to zero but i don't have the column where i can get the names instead of the id How can i achive this?? Something like the picture with the 0 or null values Thanks for any help Quote Link to comment https://forums.phpfreaks.com/topic/295925-problem-with-null-query-inner-join/ Share on other sites More sharing options...
Solution Barand Posted April 29, 2015 Solution Share Posted April 29, 2015 You are selecting four columns but show only three in the output image ??? I don't know your data structure or content so can only guess, but would a LEFT JOIN instead of INNER JOIN on `req_material_tempo` give the desired result? Quote Link to comment https://forums.phpfreaks.com/topic/295925-problem-with-null-query-inner-join/#findComment-1510230 Share on other sites More sharing options...
gmc1103 Posted April 29, 2015 Author Share Posted April 29, 2015 Hi Barand You again, thank you, it was the fix for my issue, now i have You are the man Best regards Quote Link to comment https://forums.phpfreaks.com/topic/295925-problem-with-null-query-inner-join/#findComment-1510264 Share on other sites More sharing options...
gmc1103 Posted April 29, 2015 Author Share Posted April 29, 2015 But now i have a problem running my query in php file <?php error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); include 'conn.php'; mysql_query("SET NAMES 'utf8'"); $rs = mysql_query('SELECT `semana_dias`.`dia` , `req_material_sala`.`sala` , `req_material_tempo`.`inicio` FROM sala_ocupacao INNER JOIN `semana_dias` ON (`sala_ocupacao`.`id_dia` = `semana_dias`.`id_dia`) INNER JOIN `req_material_sala` ON (`sala_ocupacao`.`id_sala` = `req_material_sala`.`idsala`) LEFT JOIN `req_material_tempo` ON (`sala_ocupacao`.`id_tempo` = req_material_tempo.`idtempo`) ORDER BY sala_ocupacao.`id_ocup`id_ocup;'); $result = array(); while($row = mysql_fetch_object($rs)){ array_push($result, $row); } echo json_encode($result); ?> i get this error </span> Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\multiple\get_ocupacao.php on line <i>16 ??? Whats wrong now i get this error Quote Link to comment https://forums.phpfreaks.com/topic/295925-problem-with-null-query-inner-join/#findComment-1510268 Share on other sites More sharing options...
Barand Posted April 29, 2015 Share Posted April 29, 2015 The last line of the query looks odd ...ORDER BY sala_ocupacao.`id_ocup`id_ocup;' Quote Link to comment https://forums.phpfreaks.com/topic/295925-problem-with-null-query-inner-join/#findComment-1510278 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.