onedumbcoder Posted December 4, 2008 Share Posted December 4, 2008 i am creating forums just for the hell of it. and i am running into an issue where the name will not print if the last name is null $query = "SELECT forum_post.title AS a, COUNT(forum_reply.id) AS b, CONCAT(user.first , ' ' , user.last) AS c FROM (forum_post LEFT JOIN forum_reply ON forum_reply.post_id=forum_post.id) LEFT JOIN user ON user.id=forum_post.creator_id WHERE forum_post.forum_id='$subject' GROUP BY forum_post.time_stamp"; Is there a way i can do a check inside the query that would allow me to replace the user.last with '' if it is null? Quote Link to comment https://forums.phpfreaks.com/topic/135484-no-printout-when-value-is-null/ Share on other sites More sharing options...
Cosizzle Posted December 4, 2008 Share Posted December 4, 2008 You could try an IF (Sorry if this is in the wrong order) im on trial and error basis with SQL but the idea is there... $query = "SELECT forum_post.title AS a, COUNT(forum_reply.id) AS b, CONCAT(user.first , ' ' , user.last) AS c FROM (forum_post LEFT JOIN forum_reply ON forum_reply.post_id=forum_post.id) LEFT JOIN user ON user.id=forum_post.creator_id WHERE forum_post.forum_id='$subject' IF user.last IS NULL THEN SET user.last = " " GROUP BY forum_post.time_stamp"; Another option would be to set (UPDATE) your user.last to have a default value of " " Quote Link to comment https://forums.phpfreaks.com/topic/135484-no-printout-when-value-is-null/#findComment-706062 Share on other sites More sharing options...
onedumbcoder Posted December 4, 2008 Author Share Posted December 4, 2008 wow thank you so much Cosizzle! I really appreciate your help Quote Link to comment https://forums.phpfreaks.com/topic/135484-no-printout-when-value-is-null/#findComment-706227 Share on other sites More sharing options...
onedumbcoder Posted December 4, 2008 Author Share Posted December 4, 2008 what if I wanted to change multiple items in the if statment? would i do this? IF user.last IS NULL THEN SET { user.last = " ", user.first = " " } Quote Link to comment https://forums.phpfreaks.com/topic/135484-no-printout-when-value-is-null/#findComment-706232 Share on other sites More sharing options...
onedumbcoder Posted December 5, 2008 Author Share Posted December 5, 2008 I actually tried to use the if statement, but it is telling me it is incorrect syntax. Can someone please verify that query would work? Quote Link to comment https://forums.phpfreaks.com/topic/135484-no-printout-when-value-is-null/#findComment-706402 Share on other sites More sharing options...
fenway Posted December 5, 2008 Share Posted December 5, 2008 Try: CONCAT_WS( ' ', (IFNULL(user.first,'') IFNULL(user.last,'')) AS c Quote Link to comment https://forums.phpfreaks.com/topic/135484-no-printout-when-value-is-null/#findComment-706476 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.