1

What should be the logic for the function below?

function check_empty($field){
  $this->_params();
  $db = $this->getDb();
  $milestone = $db->select()
    ->from('milestone')
    ->where("$field IN ('')")
    ->where("name = ?", $this->milestone['name']);

  $milestone_stmt = $db->query($milestone);
  echo $milestone->__toString();
  $milestone_result = $milestone_stmt->fetchAll();

  if(count($milestone_result) > 0) {
    return true;
  } else {
    return false;
  }
}

This is the function used to check if a field is empty. If the field is originally field and updated with the contents removed in a form the other function should insert a form but it is not inserting.

2
  • I am just new. That is why. I am also in the field. Commented Apr 1, 2011 at 4:58
  • Nope i meant that you have asked 6 questions, but you haven't accepted any of answers. On the top-left of every answers, you have tick icon. Click there if you think that was the right answer for your question. Commented Apr 1, 2011 at 5:01

1 Answer 1

1

The query will return true if it can't match any rows, false otherwise:

function check_empty($field) {
    $this->_params();
    $db = $this->getDb();
    $milestone = $db->select()
                    ->from('milestone')
                    ->where("$field = ''")
                    ->where("name = ?", $this->milestone['name']);
    $milestone_stmt = $db->query($milestone);

    //No query results means the field is not empty.
    return $milestone_stmt === false;
}
Sign up to request clarification or add additional context in comments.

2 Comments

Will there be a possibility that there is a result which is not null or a special character or something?
@efox it'll either be a statement or false. The expression milestone_stmt === false will return false if $milestone_stmt is anything other than false

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.