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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.