PHP
1function getHistories($tableNumber) 2{ 3 try { 4 $errors = array(); 5 $db = connectdb($errors); 6 $stmt = $db ->prepare("SELECT * FROM (SELECT history.productid AS productid, history.tableNumber AS tableNumber, history.quantity AS quantity, history.time AS time, 7 sushi.name AS name, sushi.price AS price, sushi.img AS img, sushi.intro AS intro 8 FROM history INNER JOIN sushi ON (history.productid = sushi.id) 9 WHERE history.tableNumber = 6 10 UNION ALL 11 SELECT history.productid AS productid, history.tableNumber AS tableNumber, history.quantity AS quantity, history.time AS time, 12 dessert.name AS name, dessert.price AS price, dessert.img AS img, dessert.intro AS intro 13 FROM history INNER JOIN dessert ON (history.productid = dessert.id) 14 WHERE history.tableNumber = 6) AS product ORDER BY product.time ASC"); 15 16 $stmt ->bindParam(1, $tableNumber, PDO::PARAM_INT); 17 $stmt ->bindParam(2, $tableNumber, PDO::PARAM_INT); 18 $stmt ->execute(); 19 $results = $stmt ->fetchAll(); 20 } catch (PDOException $e) { 21 echo "エラー:" . $e ->getMessage(); 22 } 23 return $results; 24}
という関数があります。要は取り出したSQLの文の全てを取得するという関数です。
関数自体の挙動は問題なしです。
しかし呼出し先で
$_SESSION['historiesMaxpage'] = ceil(count($$histories) / $itemperpagse);
の様に使うとエラーが出ます。ここでは行数のみが欲しいのですが、その場合はfecthColumnでないとダメですか。
fetchAllをfecthColumnに変えた関数を増やせば動くとは思いますが、この関数で呼出し先で行数を取得する方法はありますか。
あなたの回答
tips
プレビュー