Tried to make a search for items in our database, here's the code.
$SQL = $yhteys->prepare("SELECT *, COUNT(*) AS Maara FROM TuoteTiedot
INNER JOIN VarastoTuoteLista ON TuoteTiedot.TuoteID=VarastoTuoteLista.TuoteID
INNER JOIN Varastopaikat ON VarastoTuoteLista.PaikkaID=Varastopaikat.PaikkaID
WHERE '?' LIKE '?' OR '?' LIKE '?'");
$SQL->execute(array($hakuvalinta1, $haku1, $hakuvalinta2, $haku2));
$tiedot = $SQL->fetchAll();
if($SQL->execute(array($haku1, $hakuvalinta1, $haku2, $hakuvalinta2))){
if($SQL->fetchColumn() > 0){
$SQL2 = $yhteys->prepare("SELECT * FROM TuoteTiedot
INNER JOIN VarastoTuoteLista ON TuoteTiedot.TuoteID=VarastoTuoteLista.TuoteID
INNER JOIN Varastopaikat ON VarastoTuoteLista.PaikkaID=Varastopaikat.PaikkaID
WHERE '?' LIKE '?' OR '?' LIKE '?'");
$SQL2->execute(array($haku1, $hakuvalinta1, $haku2, $hakuvalinta2));
$SQL2->fetchAll();
foreach($yhteys->execute() as $row){ //this is line 55
echo $row['Nimi'] + " ";
echo $row['TuoteSeloste'] + " " ;
echo $row['Myyntihinta'];
}
}
echo "</table>";
} else {
echo 'Nothing found';
}
It gives an error on the page and it looks like this:
Fatal error: Call to undefined method PDO::execute() in (removed address) index.php on line 55
I have no idea what's wrong with it, but apparently the foreach doesn't like PDO or something like that. Kinda new with PDO but other people working on the site wanted to use it so I kinda have to use it too.
I've checked that the query works, and the previous executes work just fine.