Get specific row value from database and output into a textbox

I’m quite new with PHP, basically I want to get two values from a database from the same field but different rows. The database has the following values:

----SetupId----DayHalf-----StartTime------

--------1------------1------------07:00----------

--------2------------2------------23:00----------

In textbox 1 I want to display the value ‘07:00’ In textbox 2 I want to display the value ‘23:00’

The code I have at the moment is as follows:

[php]class OptionsController {

Functions

public static function getOptionsInfo() {

$pdo = new SQL();
$dbh = $pdo->connect(Database::$serverIP, Database::$serverPort, Database::$dbName, Database::$user, Database::$pass);

try {

    $query = "SELECT StartTime FROM tbldaysetup";

    $stmt = $dbh->prepare($query);

    $stmt->execute();

    $row = $stmt->fetch(PDO::FETCH_BOTH);

    DaySetup::set_daytime($row['StartTime']);

    $stmt->closeCursor();

}

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

$dbh = null;

}

}

?>[/php]

I then use the code below to output ‘07:00’ into the first textbox:

[php] <? echo DaySetup::get_daytime(); ?>[/php]

So how would I go about querying the database for the second value and outputting this value in a textbox. Any help to help me understand this would be much appreciated!

Well, simple way is to just add a filter to the query…

    $query = "SELECT StartTime FROM tbldaysetup WHERE SetupId=1";

Handle that input and then do it again for the section value

    $query = "SELECT StartTime FROM tbldaysetup WHERE SetupId=2";

Not sure if that is what you wanted, but, if not, you would have to give more details on where the data is coming from. If break for those two were DayHalf, then, use that instead of SetupId… Good luck…

Sponsor our Newsletter | Privacy Policy | Terms of Service