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

  • Home
  • SEARCH
  • 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 115937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:05:55+00:00 2026-05-11T03:05:55+00:00

function get_total_adults() { $sql = SELECT SUM(number_adults_attending) as number_of_adults FROM is_nfo_rsvp; $result = mysql_query($sql)

  • 0
    function get_total_adults() {     $sql = 'SELECT SUM(number_adults_attending) as number_of_adults FROM is_nfo_rsvp';     $result = mysql_query($sql) or die(mysql_error());     $array = mysql_fetch_assoc($result);      return $array['number_of_adults']; } 

I know there is a way to write this with less code. I’m just looking for the best way (without using something like ezSQL).

  • 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. 2026-05-11T03:05:56+00:00Added an answer on May 11, 2026 at 3:05 am
    function get_total_adults() {     $sql = 'SELECT SUM(number_adults_attending) FROM is_nfo_rsvp';     $result = mysql_query($sql) or die(mysql_error());     // I'd throw a catchable exception (see below) rather than die with a MySQl error      return mysql_result($result, 0); } 

    As to how I’d rather handle errors:

    function get_total_adults() {     $sql = 'SELECT SUM(number_adults_attending) FROM is_nfo_rsvp';     $result = mysql_query($sql);     if (!$result) {         throw new Exception('Failed to get total number of adults attending');     }      return mysql_result($result, 0); }  try {     $total_adults = get_total_adults(); } catch(Exception $ex) {     die('Whoops! An error occurred: ' . $ex->getMessage());     // or even better, add to your template and dump the template at this point } // continue code 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$.getJSON(./data/revenue-item-data.php,{val:'val'},function(data){ $('#totalUnits').val(data[0].SUM(item_qty)); $('#totalAmounts').val(data[0].SUM(DISTINCT net_total)); }); Here is array I get for above code: [{SUM(item_qty):68,SUM(DISTINCT
I use SQL COUNT function to get the total number or rows from a
function get_arr($arr) { unset($arr[0]); } $arr1 = array(1,2); $arr2 = array(1,2); get_arr(&$arr1); get_arr($arr2); echo
I've a php function to get some data from mysql database: function get_persons() {
I have a SQL function called get_forecast_history(integer,integer) that takes two arguments, a month and
I have this query: SELECT I1 & , & I2 AS Item_set, Round(Sum([T1].Fuzzy_Value)/Count(*),15) AS
I am trying to handle an array coming back from an ajax call. My
I have a function that adds shopping cart data to an array of arrays.
I get error: ORA-06575: Package or function GET_CONC_NAMES is in an invalid state When
Can anyone describe the following php function: function get_setting_value($settings_array, $setting_name, $default_value = ) {

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.