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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:11:10+00:00 2026-05-23T21:11:10+00:00

$sql = $connect->prepare(SELECT e.ID, u.sex FROM discos_events e INNER JOIN discos_events_guests eg ON (e.ID

  • 0
$sql = $connect->prepare("SELECT e.ID, u.sex FROM discos_events e
INNER JOIN discos_events_guests eg ON (e.ID = eg.eID)
INNER JOIN users u ON (eg.uID = u.id)
WHERE e.dID =:id");
$sql->bindValue(":id", $cID);
$sql->execute();
$total = $sql->rowCount();
$male = 0;
$female = 0;
while($sex = $sql->fetch()){
    if($sex["sex"] == "male"){
        $male++;
    }else{
        $female++;
    }
}
$averageMales = $male/$total;
$averageFemales = $female/$total;

Can this be done any simpler?

If not, this does not work properly, if there’s two males and 0 females, $averageMales return 1 and $averageFemales return 0.

I want it to return in procentages, e.g 100% now when theres not any females, and females 0%.

  • 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-05-23T21:11:11+00:00Added an answer on May 23, 2026 at 9:11 pm

    No need to use separate queries:

    SELECT count(males.id) / (count(males.id) + count(females.id)) * 100 AS male_percentage
    FROM discos_events
    JOIN discos_events_guests ON discos_events_guests.eID = discos_events.ID
    LEFT JOIN users males ON males.sex = 'male' AND males.id = discos_events_guests.uID
    LEFT JOIN users females ON females.sex = 'female' AND females.id = discos_events_guests.uID
    WHERE discos_events.dID = :id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to connect SQL Server from a Windows service. Now my Windows
I am trying to connect to SQL Server 2008 server from Java here is
Some one asked about How to connect to SQL server database from JavaScript? and
I am using LINQ to SQL to connect to database from my application. When
I am trying to connect Sql Server Data Base using windows authentication from my
I'm using LINQ to SQL to connect my database to my home page. I
I'm trying to connect to SQL Server on Ubuntu 9.04 using Ruby. I translated
Is it possible to connect to Sql Server for the purpose of executing simple
When I attempt to connect to SQL server using enterprise manager I get the
I have always thought that in order to connect to SQL server using windows

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.