Skip to main content
ajustado o bloco de código
Fonte Link
Woss
  • 77,2mil
  • 15
  • 123
  • 221

php -mostrar total calculado Undefined index ao buscar registros do banco de dados

Criei codigoum código que faz com que selecione todos os REWARDS da dbREWARDS do banco de dados, calcule e de um resultado.

  function updating_exp($con) {
             
 global $con; 

  $stmt = $con->prepare("SELECT SUM(reward_qty) AS total_earned FROM public_rewards WHERE client_id = ? AND reward_type = 'exp' LIMIT 0, 12");
  $stmt->bind_param('s', $_SESSION['u_id']);
  $stmt->execute();
  $stmt->bind_result($uid);
  $stmt->store_result();     

 $reward_exp = 15;   

if(public_user_general_data($con) == true) {

    return false;

} else {

      if(public_user_level_data($con, $reach_level = 2)) {

          if($stmt->num_rows > 0) {     

              while($results = $stmt->fetch()) {

                    $percentages = $results['total_earned'];         

                    //echo "<script>alert('$percentages');</script>"; 

                    $total = ($percentages / 100) * $reward_exp;
                    $receive = $reward_exp + round($total);

                    //echo "<script>alert('p $percentage -  r $reward_exp -  t $total / $receive');</script>";   
                    exp_user_data($con, $receive);                    
              }

          } else {
                    exp_user_data($con, $reward_exp); 
          }  

      } else {
          exp_user_data($con, $reward_exp);
      }     
}     
}
function updating_exp($con) {
             
    global $con; 

    $stmt = $con->prepare("SELECT SUM(reward_qty) AS total_earned FROM public_rewards WHERE client_id = ? AND reward_type = 'exp' LIMIT 0, 12");
    $stmt->bind_param('s', $_SESSION['u_id']);
    $stmt->execute();
    $stmt->bind_result($uid);
    $stmt->store_result();     

    $reward_exp = 15;   

    if(public_user_general_data($con) == true) {

        return false;

    } else {

        if(public_user_level_data($con, $reach_level = 2)) {

            if($stmt->num_rows > 0) {     

                while($results = $stmt->fetch()) {

                    $percentages = $results['total_earned'];         

                    //echo "<script>alert('$percentages');</script>"; 

                    $total = ($percentages / 100) * $reward_exp;
                    $receive = $reward_exp + round($total);

                    //echo "<script>alert('p $percentage -  r $reward_exp -  t $total / $receive');</script>";   
                    exp_user_data($con, $receive);                    
                }

            } else {
                exp_user_data($con, $reward_exp); 
            }  

        } else {
            exp_user_data($con, $reward_exp);
        }     
    }     
}

php -mostrar total calculado

Criei codigo que faz com que selecione todos os REWARDS da db, calcule e de um resultado.

  function updating_exp($con) {
             
 global $con; 

  $stmt = $con->prepare("SELECT SUM(reward_qty) AS total_earned FROM public_rewards WHERE client_id = ? AND reward_type = 'exp' LIMIT 0, 12");
  $stmt->bind_param('s', $_SESSION['u_id']);
  $stmt->execute();
  $stmt->bind_result($uid);
  $stmt->store_result();     

 $reward_exp = 15;   

if(public_user_general_data($con) == true) {

    return false;

} else {

      if(public_user_level_data($con, $reach_level = 2)) {

          if($stmt->num_rows > 0) {     

              while($results = $stmt->fetch()) {

                    $percentages = $results['total_earned'];         

                    //echo "<script>alert('$percentages');</script>"; 

                    $total = ($percentages / 100) * $reward_exp;
                    $receive = $reward_exp + round($total);

                    //echo "<script>alert('p $percentage -  r $reward_exp -  t $total / $receive');</script>";   
                    exp_user_data($con, $receive);                    
              }

          } else {
                    exp_user_data($con, $reward_exp); 
          }  

      } else {
          exp_user_data($con, $reward_exp);
      }     
}     
}

Undefined index ao buscar registros do banco de dados

Criei um código que faz com que selecione todos os REWARDS do banco de dados, calcule e de um resultado.

function updating_exp($con) {
             
    global $con; 

    $stmt = $con->prepare("SELECT SUM(reward_qty) AS total_earned FROM public_rewards WHERE client_id = ? AND reward_type = 'exp' LIMIT 0, 12");
    $stmt->bind_param('s', $_SESSION['u_id']);
    $stmt->execute();
    $stmt->bind_result($uid);
    $stmt->store_result();     

    $reward_exp = 15;   

    if(public_user_general_data($con) == true) {

        return false;

    } else {

        if(public_user_level_data($con, $reach_level = 2)) {

            if($stmt->num_rows > 0) {     

                while($results = $stmt->fetch()) {

                    $percentages = $results['total_earned'];         

                    //echo "<script>alert('$percentages');</script>"; 

                    $total = ($percentages / 100) * $reward_exp;
                    $receive = $reward_exp + round($total);

                    //echo "<script>alert('p $percentage -  r $reward_exp -  t $total / $receive');</script>";   
                    exp_user_data($con, $receive);                    
                }

            } else {
                exp_user_data($con, $reward_exp); 
            }  

        } else {
            exp_user_data($con, $reward_exp);
        }     
    }     
}
  function updating_exp($con) {
             
 global $con; 

  $stmt = $con->prepare("SELECT SUM(reward_qty) AS total_earned FROM public_rewards WHERE client_id = ? AND reward_type = 'exp' LIMIT 0, 12");
  $stmt->bind_param('s', $_SESSION['u_id']);
  $stmt->execute();
  $stmt->bind_result($uid);
  $stmt->store_result();     

 $reward_exp = 15;   

if(public_user_general_data($con) == true) {

    return false;

} else {

      if(public_user_level_data($con, $reach_level = 2)) {

          if($stmt->num_rows > 0) {     

              while($results = $stmt->fetch()) {

                    $percentages = $results['total_earned'];         

                    //echo "<script>alert('$percentages');</script>"; 

                    $total = ($percentages / 100) * $reward_exp;
                    $receive = $reward_exp + round($total);

                    //echo "<script>alert('p $percentage -  r $reward_exp -  t $total / $receive');</script>";   
                    exp_user_data($con, $receive);                    
              }

          } else {
                    exp_user_data($con, $reward_exp); 
          }  

      } else {
          exp_user_data($con, $reward_exp);
      }     
}     

}

  function updating_exp($con) {
             
 global $con; 

  $stmt = $con->prepare("SELECT SUM(reward_qty) AS total_earned FROM public_rewards WHERE client_id = ? AND reward_type = 'exp' LIMIT 0, 12");
  $stmt->bind_param('s', $_SESSION['u_id']);
  $stmt->execute();
  $stmt->bind_result($uid);
  $stmt->store_result();     

 $reward_exp = 15;   

if(public_user_general_data($con) == true) {

    return false;

} else {

      if(public_user_level_data($con, $reach_level = 2)) {

          if($stmt->num_rows > 0) {     

              while($results = $stmt->fetch()) {

                    $percentages = $results['total_earned'];         

                    //echo "<script>alert('$percentages');</script>"; 

                    $total = ($percentages / 100) * $reward_exp;
                    $receive = $reward_exp + round($total);

                    //echo "<script>alert('p $percentage -  r $reward_exp -  t $total / $receive');</script>";   
                    exp_user_data($con, $receive);                    
              }

          } else {
                    exp_user_data($con, $reward_exp); 
          }  

      } else {
          exp_user_data($con, $reward_exp);
      }     
}     
}
  function updating_exp($con) {
             
 global $con; 

  $stmt = $con->prepare("SELECT SUM(reward_qty) AS total_earned FROM public_rewards WHERE client_id = ? AND reward_type = 'exp' LIMIT 0, 12");
  $stmt->bind_param('s', $_SESSION['u_id']);
  $stmt->execute();
  $stmt->bind_result($uid);
  $stmt->store_result();     

 $reward_exp = 15;   

if(public_user_general_data($con) == true) {

    return false;

} else {

      if(public_user_level_data($con, $reach_level = 2)) {

          if($stmt->num_rows > 0) {     

              while($results = $stmt->fetch()) {

                    $percentages = $results['total_earned'];         

                    //echo "<script>alert('$percentages');</script>"; 

                    $total = ($percentages / 100) * $reward_exp;
                    $receive = $reward_exp + round($total);

                    //echo "<script>alert('p $percentage -  r $reward_exp -  t $total / $receive');</script>";   
                    exp_user_data($con, $receive);                    
              }

          } else {
                    exp_user_data($con, $reward_exp); 
          }  

      } else {
          exp_user_data($con, $reward_exp);
      }     
}     

}

  function updating_exp($con) {
             
 global $con; 

  $stmt = $con->prepare("SELECT SUM(reward_qty) AS total_earned FROM public_rewards WHERE client_id = ? AND reward_type = 'exp' LIMIT 0, 12");
  $stmt->bind_param('s', $_SESSION['u_id']);
  $stmt->execute();
  $stmt->bind_result($uid);
  $stmt->store_result();     

 $reward_exp = 15;   

if(public_user_general_data($con) == true) {

    return false;

} else {

      if(public_user_level_data($con, $reach_level = 2)) {

          if($stmt->num_rows > 0) {     

              while($results = $stmt->fetch()) {

                    $percentages = $results['total_earned'];         

                    //echo "<script>alert('$percentages');</script>"; 

                    $total = ($percentages / 100) * $reward_exp;
                    $receive = $reward_exp + round($total);

                    //echo "<script>alert('p $percentage -  r $reward_exp -  t $total / $receive');</script>";   
                    exp_user_data($con, $receive);                    
              }

          } else {
                    exp_user_data($con, $reward_exp); 
          }  

      } else {
          exp_user_data($con, $reward_exp);
      }     
}     
}
Fonte Link

php -mostrar total calculado

Criei codigo que faz com que selecione todos os REWARDS da db, calcule e de um resultado.

  function updating_exp($con) {
             
 global $con; 

  $stmt = $con->prepare("SELECT SUM(reward_qty) AS total_earned FROM public_rewards WHERE client_id = ? AND reward_type = 'exp' LIMIT 0, 12");
  $stmt->bind_param('s', $_SESSION['u_id']);
  $stmt->execute();
  $stmt->bind_result($uid);
  $stmt->store_result();     

 $reward_exp = 15;   

if(public_user_general_data($con) == true) {

    return false;

} else {

      if(public_user_level_data($con, $reach_level = 2)) {

          if($stmt->num_rows > 0) {     

              while($results = $stmt->fetch()) {

                    $percentages = $results['total_earned'];         

                    //echo "<script>alert('$percentages');</script>"; 

                    $total = ($percentages / 100) * $reward_exp;
                    $receive = $reward_exp + round($total);

                    //echo "<script>alert('p $percentage -  r $reward_exp -  t $total / $receive');</script>";   
                    exp_user_data($con, $receive);                    
              }

          } else {
                    exp_user_data($con, $reward_exp); 
          }  

      } else {
          exp_user_data($con, $reward_exp);
      }     
}     

}

mas ele da erro

 Notice: Undefined index: total_earned in D:\xampp\htdocs\Superfacil_v1.4\inc\functions.php on line 586