Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP / MySQL - Query loop?
    text
    copied!<p>I have the following function:</p> <pre><code>private static function getFixedFare($FixedFareId) { $pdo = new SQL(); $dbh = $pdo-&gt;connect(Database::$serverIP, Database::$serverPort, Database::$dbName, Database::$user, Database::$pass); try { $query = "SELECT Fare FROM tblfixedfare WHERE FixedFareId = :fixed_fare_id AND DayHalf = :day_half"; $stmt = $dbh-&gt;prepare($query); $stmt-&gt;bindParam(':fixed_fare_id', $FixedFareId, PDO::PARAM_INT); $stmt-&gt;bindParam(':day_half', self::$day_half, PDO::PARAM_STR); $stmt-&gt;execute(); $result = $stmt-&gt;fetch(PDO::FETCH_COLUMN); $stmt-&gt;closeCursor(); $dbh = null; return $result; } catch (PDOException $pe) { die("Error: " .$pe-&gt;getMessage(). " Query: ".$stmt-&gt;queryString); } } </code></pre> <p>Basically I want to change the query to do nine different selects, as follows:</p> <pre><code> $query = "SELECT Fare FROM tblfixedfare WHERE FixedFareId = :fixed_fare_id AND DayHalf = :day_half AND CarType = 'Car'"; </code></pre> <p>and</p> <pre><code> $query = "SELECT Fare FROM tblfixedfare WHERE FixedFareId = :fixed_fare_id AND DayHalf = :day_half AND CarType = 'Est'"; </code></pre> <p>and the same for all the other car types, 'Exec', 'ExecEst', '6B', '7B', '7W', '8B' and 'Bus' which will only ever be these car types.</p> <p>I was hoping I could store each of these query results into different variables without having to do 9 different queries (reducing code). Such as a loop and then storing the results to $resultcar, $resultest and so on...</p> <p>Not to sure how I would do this so any help would be much appreciated! :-)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload