troubleshooting Question

MySql Query Help

Avatar of Mada123
Mada123Flag for United States of America asked on
PHP
3 Comments1 Solution276 ViewsLast Modified:
I have been beating my head over this for the last two days and need help.

Here's my code
// Get Adult Family Information
          //First Get all the IDs for adults and children, Marriage and Divorce Dates and Places
if ($BGen == "M") {
 $Q_GetFam = "
SELECT
   tng_families.familyID, tng_families.wife, tng_families.marrdate, tng_families.marrplace, tng_families.gedcom, tng_families.divdate, tng_families.divplace, tng_families.wifeorder, tng_children.gedcom, tng_children.familyID, tng_children.personID, tng_children.ordernum
FROM
  tng.tng_families INNER JOIN tng.tng_children ON tng_families.gedcom = tng_children.gedcom AND tng_families.familyID = tng_children.familyID
WHERE
  tng_families.gedcom = '$tree' AND tng_families.husband = '$personID'
ORDER BY
  tng_families.wifeorder, tng_children.ordernum
";

$R_GetFam = mysql_query ($Q_GetFam) or  die ("Unable to execute Q_GetFam.  Error: ".mysql_error());
    while ($row = mysql_fetch_array($R_GetFam))
		{
		$GFW = $row['wife'];
		$GFMD = $row['marrdate'];
		$GFMP = $row['marrplace'];
		$GFDvD = $row['divdate'];
		$GFDvP = $row['divplace'];
		$GFCh = $row['personID'];
  // Link Wives' ID(s) (GFW) with first and last name.
 $Q_GetW = "
SELECT
  tng_people.gedcom, tng_people.lastname, tng_people.firstname, tng_people.personID
FROM
  tng.tng_people
WHERE
  tng_people.gedcom = '$tree' AND tng_people.personID = '$GFW'
  Group By   tng_people.personID
";
$R_GetW = mysql_query ($Q_GetW) or  die ("Unable to execute Q_GetW.  Error: ".mysql_error());
    while ($row = mysql_fetch_array($R_GetW))
		{
		$GFWFN = $row['firstname'];
		$GFWLN = $row['lastname'];
        $STSH .= "<p>$AFN $ALN married $GFWFN $GFWLN on $GFMD in $GFMP";
	}
    // Link all the children's ids (GFCH) with their first names
if ($GFCh == "") {$STSI = "No Issue.";} else {
  $STSIa = " Together, they had the following children: ";
 $Q_GetCh = "
SELECT
  tng_people.gedcom, tng_people.firstname, tng_people.personID
FROM
  tng.tng_people
WHERE
  tng_people.gedcom = '$tree' AND tng_people.personID = '$GFCh'
";
$R_GetCh = mysql_query ($Q_GetCh) or  die ("Unable to execute Q_GetCh.  Error: ".mysql_error());
    while ($row = mysql_fetch_array($R_GetCh))
		{
		$GFCFN = $row['firstname'];
          $STSI .= "$GFCFN,";
	}
}
		}

}

Here's the output of $Q_GetFam - I get everyone's ids like I wanted...
 Reult of  $Q_GetFam
This is the mess that finally comes out.
 Webpage

Here's what I want...

John McPeek married Rachel Boss on 4 Jan 1814 in Sussex County, New Jersey. Together, they had the following children: Jonathan, Electa, Richard, Lucretia, Catherine, Elizabeth.

John McPeek married Susan Evaline Jayne on 1834. Together,  they had the following children: Rachel, Phebe A, Caroline B, John B, Mary J, Eliza E, Louise E, David S, Cornelius.

Can you please help?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros