I´m trying to get uses to the PHP PDO Syntax. Maybe somone can have a look at this peace of code. It seems it´s a bit much lines for little effort.
I catch a User Post-Input (ID). Know I need for calculation reason the values BejagFlach from all Users (the sum of them) and the single value BejagFlach from the User identified by the ID. Do I need two querys for this like here? or is there are shorter/better way?
/* Fetch POST Data */
$User_Num = $_POST['User_Num'];
/* Build query for one User */
$dbSelect = $objDb->prepare("SELECT BejagFlach,Name FROM Benutzer WHERE lfdNr = :User_Num");
$dbSelect -> setFetchMode(PDO::FETCH_ASSOC);
$dbSelect->execute(array(':User_Num' => $User_Num));
/* Build query for all Users */
$dbSelect2 = $objDb->prepare("SELECT BejagFlach FROM Benutzer");
$dbSelect2 -> setFetchMode(PDO::FETCH_ASSOC);
$dbSelect2->execute();
/* Output + Calculate */
while($row = $dbSelect->fetch()) {
$totalUser += $row['BejagFlach'];
$who = utf8_encode($row['Name']);
}
/* Output + Calculate */
while($row = $dbSelect2->fetch()) {
$totalAll += $row['BejagFlach'];
}
Kind regards, toni