0

How to ignore null value while fetching the data from database table php mysql. Anyone please help me

My mysql query is :

$sql = "SELECT  DISTINCT cuid FROM temp_donor_list WHERE donor_no='$name'";
0

2 Answers 2

1

Try this below code

$sql = "SELECT DISTINCT cuid FROM temp_donor_list WHERE donor_no='$name' and cuid!='' and donor_no!=''";
Sign up to request clarification or add additional context in comments.

2 Comments

''(blank) is not equal to NULL. NULL is special value so you can not compare with blank string
This query executed correctly: $sql = "SELECT DISTINCT cuid FROM temp_donor_list WHERE donor_no='$name' AND cuid!=' '";
1
  1. If your field contains NULL value then you can use IS NOT NULL condtion.

  2. If your field contains blank string then you can use <> opertor

    SELECT DISTINCT cuid FROM temp_donor_list WHERE donor_no='$name' AND cuid IS NOT NULL AND cuid<>''

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.