if (strlen($search) > 0)
{
$query = "SELECT p.product_id,p.account_id,i.image_id,a.email,p.title,p.price,MATCH(p.title) AGAINST('?' IN BOOLEAN MODE) AS score
FROM products AS p
LEFT OUTER JOIN products_images AS i
ON p.product_id = i.product_id AND i.featured=1 AND i.deleted=0
INNER JOIN accounts AS a
ON p.account_id = a.account_id
WHERE MATCH(p.title) AGAINST('?' IN BOOLEAN MODE)
ORDER BY score DESC";
}
else
{
$query = "SELECT p.product_id,p.account_id,i.image_id,a.email,p.title,p.price
FROM products AS p
LEFT OUTER JOIN products_images AS i
ON p.product_id = i.product_id AND i.featured=1 AND i.deleted=0
INNER JOIN accounts AS a
ON p.account_id = a.account_id";
}
//Search the listings
echo "<div class=\"row\">";
if ($statement = $mysqli->prepare($query))
{
if (strlen($search) > 0)
{
$statement->bind_param("ss", $search, $search);
}
$statement->execute();
}
This confuses me greatly but, if there is a $search provided, it spits out an error saying that "number of variables doesn't match number of parameters in prepared statement".
The other case where there is no $search works fine.
This is very confusing because there are two ?? and I bind two strings as parameters. Don't really understand what is happening.
It's very confusing, but you can try:
if (strlen($search) > 0)
{
$query = "SELECT p.product_id,p.account_id,i.image_id,a.email,p.title,p.price,MATCH(p.title) AGAINST('?' IN BOOLEAN MODE) AS score
FROM products AS p
LEFT OUTER JOIN products_images AS i
ON p.product_id = i.product_id AND i.featured=1 AND i.deleted=0
INNER JOIN accounts AS a
ON p.account_id = a.account_id
WHERE MATCH(p.title) AGAINST(:ss IN BOOLEAN MODE)
ORDER BY score DESC";
}
else
{
$query = "SELECT p.product_id,p.account_id,i.image_id,a.email,p.title,p.price
FROM products AS p
LEFT OUTER JOIN products_images AS i
ON p.product_id = i.product_id AND i.featured=1 AND i.deleted=0
INNER JOIN accounts AS a
ON p.account_id = a.account_id";
}
//Search the listings
echo "<div class=\"row\">";
if ($statement = $mysqli->prepare($query))
{
if (strlen($search) > 0)
{
$statement->bind_param(':ss', $search);
}
$statement->execute();
}