First of all, if these type of questions aren't allowed, please tell me.
Here's some code from a year or so ago:
$search_sql = "SELECT Name, Amount, CardID FROM modernmasters WHERE";
$keywords = explode(" ", $query);
$keyCount = 0;
foreach ($keywords as $keys) {
if ($keyCount > 0){
$search_sql .= " AND";
}
$search_sql .= " Name LIKE '%$keys%'";
++$keyCount;
}
If you excuse the fact that it's from the deprecated mysql_ functions I just want to make sure I understand what it means.
$search_sql = "SELECT Name, Amount, CardID FROM modernmasters WHERE";
$keywords = explode(" ", $query);
Nothing too hard to understand, it's just a basic fetch query with the explode function that separates spaces with the $search_sql
string.
$keyCount = 0;
foreach ($keywords as $keys) {
if ($keyCount > 0){
$search_sql .= " AND";
}
$search_sql .= " Name LIKE '%$keys%'";
++$keyCount;
}
This sets the $keyCount
to 0, and then it goes into a foreach loop. This is where I'm not too sure,
if ($keyCount > 0){
$search_sql .= " AND";
}
Does this mean when the $keyCount
(each word in the array) is above 0 it tacks on " AND" in the statement?
For example:
$keyCount
= 1;
"SELECT Name, Amount, CardID FROM modernmasters WHERE Name LIKE '%$keys%'";
$keyCount
= 2;
"SELECT Name, Amount, CardID FROM modernmasters WHERE Name LIKE '%$keys%' AND Name LIKE '%$keys%'";
So for each word I search for it will add " AND Name LIKE '%$keys%'"
, right?
Or am I totally reading this wrong?