Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8892159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:55:26+00:00 2026-06-14T22:55:26+00:00

I have the following function: private static function getFixedFare($FixedFareId) { $pdo = new SQL();

  • 0

I have the following function:

private static function getFixedFare($FixedFareId) {

    $pdo = new SQL();
    $dbh = $pdo->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->prepare($query);

        $stmt->bindParam(':fixed_fare_id', $FixedFareId, PDO::PARAM_INT);
        $stmt->bindParam(':day_half', self::$day_half, PDO::PARAM_STR);

        $stmt->execute();

        $result = $stmt->fetch(PDO::FETCH_COLUMN);

        $stmt->closeCursor();

        $dbh = null;

        return $result;

    }

    catch (PDOException $pe) {
        die("Error: " .$pe->getMessage(). " Query: ".$stmt->queryString);
    }

}

Basically I want to change the query to do nine different selects, as follows:

        $query =   "SELECT Fare FROM tblfixedfare
                    WHERE FixedFareId = :fixed_fare_id
                    AND DayHalf = :day_half
                    AND CarType = 'Car'";

and

        $query =   "SELECT Fare FROM tblfixedfare
                    WHERE FixedFareId = :fixed_fare_id
                    AND DayHalf = :day_half
                    AND CarType = 'Est'";

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.

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…

Not to sure how I would do this so any help would be much appreciated! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:55:28+00:00Added an answer on June 14, 2026 at 10:55 pm

    You can do an IN

    SELECT CarType, Fare FROM tblfixedfare
    WHERE FixedFareId = :fixed_fare_id
    AND DayHalf = :day_half
    AND CarType IN ('Car', 'Est' ...);
    

    Note that you have to include the CarType in the Select so you can filter them after the query.

    UPDATED: You can group your results by CarType already like this:

     $results = $stmt->fetchAll(PDO::FETCH_ASSOC|PDO::FETCH_GROUP);
    

    The code above should give you something like:

    array(
        'Car' => array(
            // data
        ),
        'Est' => array(
             // data
        )
    )
    

    If you don’t mind changing your variables, you can immediately have them in variables without looping through extract(…)

    So feeding

    $results = $stmt->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP);
    

    which is the array mentioned above to extract:

    extract($results, EXTR_PREFIX_ALL, 'result');
    

    will let you have the result sets in variables already:

    var_dump($result_Car);
    array(2) {
        [0]=> array(1) {
            ["Fare"]=> string(1) "100"
        }
        [1]=>
        array(1) {
            ["Fare"]=> string(1) "200"
        }
    }
    

    All in all, in one line:

    extract($q->fetchAll(PDO::FETCH_ASSOC|PDO::FETCH_GROUP), EXTR_PREFIX_ALL, 'result');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function: static private Image CropRotate(Image wholeImage, Rectangle cropArea) { Bitmap
I have the following function: private static void prettyPrint(Document doc, File destFile) { TransformerFactory
have the following FV function private static function fv($r,$n,$p,$pv=0) { $sum = $pv; for
Have following kernel function: private static String programSource = __kernel void sampleKernel(__global float *Y,
I have the following function private Integer calculateWeeklyValue(String p_Value, String Frequency) { if (p_Value.length()
I have the following simple function: private void EnableDisable941ScheduleBButton() { if (this._uosDepositorFrequency.Value != null)
I have the following function using Excel 2010: Private Function MakeAllSheetsValuesOnly(targetBookName As String) If
If I have the following registry class: Class registry { private $_vars; public function
In my program I have coded the following private variables and function. private string
I have the following Singleton Class in PHP. class CounterBalance{ private static $instance; private

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.