Reputation: 167
I am trying to create a query that will compare an email with ones from a table and return the amount of matches it finds.
$checkMail = $this->_filteredData['AccountEmail'];
$query = "SELECT count(*) FROM AccountDetails WHERE AccountEmail=?";
$values = array($checkMail);
$this->_DBO->runSelectQuery($query, $values, true);
/////// This is In A Different Class
public function runSelectQuery($query, $values = array(), $returnResults = false)
{
$sth = $this->_DBO->prepare($query);
$sth->execute($values);
}
My problem is that I don't know how to finish it up, I need to work out how many matches it found.
There will only be 1 match if any as emails are unique in the table so it will either return 0 or 1. If it returns one I also need to get the other data from the table, its password value and its id number.
I don't know if this is the right way to go about doing this so any feedback will be appreciated.
Thanks
Chris
Upvotes: 0
Views: 80
Reputation: 5001
you need to use a
$count = $sth->fetchColumn()
to get the return from the select statement
I am not sure what you want $returnResults to have in it but this might just be what I put in the $count variable
Upvotes: 1
Reputation: 56
Just specify the password and ID value in the same query. It will either return a result or it won't if there is no match.
$query = "SELECT id, password FROM AccountDetails WHERE AccountEmail=? LIMIT 1";
Upvotes: 1