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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:01:45+00:00 2026-06-15T12:01:45+00:00

So, I am trying to pull a first name, last name and donortype from

  • 0

So, I am trying to pull a first name, last name and donortype from 2 tables. Basically, a person has a primary “donortype”. Meaning if they are two different donortypes then in the Donor table you put the one with the highest rank. In the DonorandType table you put all the remaining. So if they are a board member, alumni and parent you would see board member in the donor table and then alumni and parent in the other table.

I end up getting all the people in the donorandtype table(I only put 4 people in there for testing each with a different number of types) showing up continually. However, if I choose 2011(last years fiscal year) they don’t repeat. However, in 2012(this fiscal year) they do. If you would prefer I show all my code and not just the piece about the sql statement and while loop I can. However, I don’t think it is an issue with my date constraint.

I also have some date constraints in my sql statement but I don’t think that should make a difference. It basically just checks the fiscal year and if they haven’t donated that year it doesn’t show them. I have tried it with and without that part of the SQL statement and it doesn’t seem to make a difference. So, I believe that part can be ignored.

Donor Table:

  • DonorID (PK)
  • FirstName
  • LastName
  • Email
  • Phone
  • DonorType (FK)

DonorType Table:

  • DonorTypeID (PK) — This is a 2 letter abbreviation of the donortype ex: AL for Alumni
  • DonorType — These are the names of each donor, 8 in total
  • Rank — Basic rank 1,2,3 and so on of importance

DonorandType Table:

  • DonorID (FK)
  • DonorType(FK)

Donation Table:

  • DonationID (PK)
  • DonationAmount
  • Restriction
  • Description
  • DateReceived
  • DonorID(FK)

Ok, so I want to pull their first name & last name from donor table. Then pull all their donortype’s from the DonorandType table.

// SQL query to interact with info from our database
$sql = mysql_query("
    SELECT donor.FirstName, donor.LastName, donorandtype.DonorType
    FROM donor, donortype, donorandtype, donations
    WHERE donor.DonorID = donorandtype.DonorID
      and donortype.DonorType = donorandtype.DonorType
      and donations.Date_Received BETWEEN '" . $startdate . "' and '" . $enddate . "'
") or die (mysql_error()); 

// Establish the output variable
echo "<table border=\"1\" cellpadding=\"10\" >
        <tr>
    <th id='name'>Donor Name</th>
    <th id'dontype'>Donor Type</th>
  </tr>";
while($row = mysql_fetch_array($sql)){ 

    $first_name = $row["FirstName"];
    $last_name = $row["LastName"];
    $donor_type = $row["DonorType"];

    echo "
    <tr>
    <td> $first_name $last_name </td>
    <td>$donor_type </td>
    </tr>";


}
echo '</table>';

This part actually displays in a table…does that need to be said? I think it is clear from the code above but whatever.

DONOR'S TYPES
Donor Name  Donor Type
Henry Hunt  Alumni
Henry Hunt  Board member
Paul Gates  Past Parent
Winifred Gardner    Parent
....
</trim>
  • 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-15T12:01:46+00:00Added an answer on June 15, 2026 at 12:01 pm
    <?php
    // SQL query to interact with info from our database
    $sqlTpl = 'SELECT `d`.`FirstName`, `d`.`LastName`, `t`.`DonorType`
               FROM
                 `donorandtype` AS `j`
                 LEFT JOIN `donor` AS `d` ON ( `j`.`DonorID` = `d`.`DonorID` )
                 LEFT JOIN `donortype` AS `t` ON ( `j`.`DonorType` = `t`.`DonorTypeID` )
                 LEFT JOIN `donations ` AS `m` ON ( `d`.`DonorID` = `m`.`DonorID` )
               WHERE
                 `m`.`Date_Received` BETWEEN "%s" AND "%s"
               ORDER BY
                 `d`.`DonorID` , `t`.`Rank`';
    $sqlStr = sprintf( $sqlTpl ,
                date( 'Y-m-d h:i:s' , strtotime( $startdate ) ) ,
                date( 'Y-m-d h:i:s' , strtotime( $enddate ) ) );
    $sqlRes = mysql_query( $sqlStr );
    
    if( !$sqlRes ){
      echo 'SQL Error Occurred:';
      echo 'But I am not going to show the error messages publicly.';
    }else{
    ?>
    <table border="1" cellpadding="0">
      <thead>
        <tr>
          <th id="name">Donor Name</th>
          <th id="type">Donor Type</th>
        </tr>
      </thead>
      <tfoot>
        <tr>
          <th colspan="2"><?php echo mysql_num_rows( $sqlRes ); ?> Donors Found</th>
        </tr>
      </tfoot>
      <tbody>
    <?php
      if( mysql_num_rows( $sqlRes ) ){
        while( $r = mysql_fetch_array( $sqlRes ) ){
    ?>
        <tr>
          <td><?php echo $r['FirstName'].' '.$r['LastName']; ?></td>
          <td><?php echo $r['DonorType']; ?></td>
        </tr>
    <?php
        }
      }else{
    ?>
        <tr>
          <td colspan="2">No Records Returned</td>
        </tr>
    <?php
      }
    ?>
      </tbody>
    </table>
    <?php
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Javascript, I am trying to take a full name (First, Middle, and Last)
I am trying to split a name that I pull from a webpage using
I'm trying to pull multiple rows from different tables in a database. If I
Just trying to pull off some SMART info from connected Hard Drives on any
I'm trying to pull data from the YouTube API into a local MySQL table.
I am trying to pull a specific set of records from a table called
I am trying to pull an LDAP jpegPhoto attribute from an openLDAP server using
I'm trying to pull a project from git, in particular, this one: https://github.com/pocmo/Yaaic .
I am trying to pull in information from Asana API via JQuery.ajax() method. But
I am trying to pull text from another page (ajaxuseradd.psp) which is in JSON

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.