Hi, I have a family database, and I am having trouble displaying a family member that has more than one child.

$bw=$_GET["id"];

mysql_pconnect("localhost","user","password");

mysql_select_db("database");


$result = mysql_query("SELECT * FROM Members WHERE id='$id'");
$row = mysql_fetch_array ($result, MYSQL_ASSOC);
echo "Member: ";
$result2 = mysql_query("SELECT * FROM spouse WHERE mid='$id'");
$row2 = mysql_fetch_array ($result2, MYSQL_ASSOC);
$result3 = mysql_query("SELECT * FROM child WHERE mid='$id'");
$row3 = mysql_fetch_array ($result3, MYSQL_ASSOC);


echo $row;
echo " ";
echo $row;
echo "<p></p>Family Information:";
if(mysql_num_rows($result2)==1){
echo " Spouse: ";
echo $row2;
echo " ";
echo $row2;
}
if(mysql_num_rows($result3)==0){}
elseif(mysql_num_rows($result3)==1){
echo " Child: ";
echo $row3;
echo " ";
echo $row3;
} else {
echo $row3;
echo " ";
echo $row3; }

1. What if $result3 returns more than 1 row ? It will never enter the condition elseif(mysql_num_rows($result3) == 1) 2. $bw = $_GET;
and $id is empty.

The script looks for 1 record because I want it to say CHILD and if there are 2 or more it should say CHILDREN. For id, the value is set via url. i.e. member.php?id=2.
I just need to know how to echo the kids names when there are 2 or more records.

I can see you are setting it via url. But you are not assigning the value to $id, but $bw. So, none of your queries will work (unless you have register globals turned on!)
Can you be more specific ? Are you getting any error ?

I can see you are setting it via url. But you are not assigning the value to $id, but $bw. So, none of your queries will work (unless you have register globals turned on!)
Can you be more specific ? Are you getting any error ?

Thanks for pointing that out. The queries were working even with that mistake so I assume I have register globals turned on. I am trying to get php to echo all of the kids that a specific member has. As an example, Amy with id 1 has two kids: Ben and Greg. I can't get the script to echo both names. Right now it displays Ben but not Greg. I know I have to use mysql_fetch_array to get the multiple records but I can't seem to figure out how to display all of them.

Ah! you need to use a while loop for that.

while($row = mysql_fetch_array($result)) {
 echo $row['columnname'];
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.