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 8346007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:52:08+00:00 2026-06-09T06:52:08+00:00

I´m trying to get uses to the PHP PDO Syntax. Maybe somone can have

  • 0

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

  • 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-09T06:52:09+00:00Added an answer on June 9, 2026 at 6:52 am

    Since you need at least your second query, I would do like this so you do only 1request to the database :

    $dbSelect =  $objDb->prepare("SELECT BejagFlach,lfdNr FROM Benutzer");
    $dbSelect -> setFetchMode(PDO::FETCH_ASSOC);  
    $dbSelect ->execute();
    while($row = $dbSelect->fetch()) {  
        $totalAll +=  $row['BejagFlach'];
        if( $row['lfdNr'] == $UserNom) {
            $totalUser += $row['BejagFlach'];
            $who = utf8_encode($row['Name']);
        }
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get this expression to work, can someone look at it and tell
I have been trying to get the following code working. It's a progress bar
I'm trying to get a tracking script working that uses AJAX via JQuery. This
I have a php script that is triggered from my app. This script uses
When trying to build a simple test program that uses atomic operations, I get
This is maybe a simple syntax question or possibly a best-practices question in terms
All, I'm trying to find out, unambiguously, what method (GET or POST) Flash/AS2 uses
I am trying to refactor old PHP project, and this project does not access
I need some help structuring my php. I am trying to get 3 different
OK, I have been trying to figure this out for a while. I just

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.