Just parsing a file and building a query BUT the $row only returns me one result, where is hold get A result per query i make.
while (!feof($f)) {
$contents = '';
$contents = fgets($f);
$p = explode(" ", $contents);
$req = "SELECT id_product from ps_product WHERE `reference`='".$p[1]."'";
$rs = $dbh->prepare($req);
$rs->execute();
$row = $rs->fetch();
print_r($row);
}
I am only getting one result at the end
My debug is like this :
M0852
PDOStatement Object ( [queryString] => SELECT id_product from ps_product WHERE `reference`='M0852 ' )
M0850
PDOStatement Object ( [queryString] => SELECT id_product from ps_product WHERE `reference`='M0850 ' )
M0850
PDOStatement Object ( [queryString] => SELECT id_product from ps_product WHERE `reference`='M0850 ' )
M0851
PDOStatement Object ( [queryString] => SELECT id_product from ps_product WHERE `reference`='M0851 ' )
M0851
PDOStatement Object ( [queryString] => SELECT id_product from ps_product WHERE `reference`='M0851 ' )
M0855
PDOStatement Object ( [queryString] => SELECT id_product from ps_product WHERE `reference`='M0855 ' )
M0849
PDOStatement Object ( [queryString] => SELECT id_product from ps_product WHERE `reference`='M0849 ' )
Array ( [id_product] => 2662 [0] => 2662 )
when I am expecting to get one array with results per query.
$rowoutside of the loop you want the 1 row per return?$row[] = $rs->fetch();, still could just be done with 1 query though using thein().fetch()only returns 1 row. If you want all rows, usefetchAll()