Jump to content

No printout when value is null


onedumbcoder

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/135484-no-printout-when-value-is-null/
Share on other sites

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 " "

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.