Hi,

This is my first post.. I hope someone can understand me and help..

I am building a dynamic php form (with mysql) with parent-child relationship.. The form should be like:

Parent_id Parent_descrition
child_col1 child col2
child_col1 child_col2

Parent_id Paren_description
child_col1 child_col2

etc...

I am successful with the first set of parent_child rows, then my next parent shows and I do not get the matching children..

I think I need to reset something after the child while loop, but I'm not sure what or how....here is a copy of the php code::

<?php
mysql_select_db($database_connsurvey, $connsurvey);
$query_sets_records = "SELECT title, description FROM webinar_master";
$sets_records = mysql_query($query_sets_records, $connsurvey) or die(mysql_error());
$row_sets_records = mysql_fetch_assoc($sets_records);
$totalRows_sets_records = mysql_num_rows($sets_records);

$query_sets_child = 
	"SELECT date, time, title FROM webinar_schedule
	 where title= " ."'". $row_sets_records['title']."'";
$sets_child = mysql_query($query_sets_child, $connsurvey) or die(mysql_error());
$row_sets_child = mysql_fetch_assoc($sets_child);
$totalRows_sets_child = mysql_num_rows($sets_child);


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

  <tr>
    <th scope="col">Title </th>
    <th scope="col">Description</th>
  </tr>


  <?php do { ?>

  <tr>
	<td> <hr /> </td> 
	<td> <hr /> </td>
	</tr>

<tr>
  <td><?php echo $row_sets_records['title']; ?></td>
  <td><?php echo $row_sets_records['description']; ?></td>
</tr>



<!--This is the child table / date time -->
		<tr>
			<table width="100%" border="0" cellspacing="0" cellpadding="0">

			 <tr>
			 <th scope="col">Date </th>
			 <th scope="col">Time</th>
			 </tr>
			<?php do {  ?>
				 <tr>
 			 <td><?php echo "parent title " . $row_sets_records['title']?>
			 	<?php echo "child title " . $row_sets_child['title']?>
				<?php echo "rows" . $totalRows_sets_child ?>
			 <?php echo $row_sets_child['date']; ?></td>
  				<td><?php echo $row_sets_child['time']; ?></td>
			 </tr>

		 <?php } while ($row_sets_child = mysql_fetch_assoc($sets_child)); ?>
		</table>

	</tr>
<!--end child table -->

<?php } while ($row_sets_records = mysql_fetch_assoc($sets_records)); ?>
</table>

</body>
</html>

<?php
mysql_free_result($sets_records);
?>
<?php
mysql_free_result($sets_child);
?>

Thanks for some assistance in this matter..
Angela

    Thanks for the article... I guess you are suggesting a alter the structure of my database and/or my queries..

    I did finally get the relationships to work and display properly..

      If you're going to need to display your parent-child relationships in different formats, then yes, you may want to consider something else. If this is as far as your display will go, then you'll be fine with this structure as you got it working.

      I personally like the adjacency list model in the right situations - I use it and have menu classes with recursive functions that display breadcrumbs, nested lists, siblings, children, etc and all integrated with CSS. But getting to that point was no easy task.

      Glad you got this working. Please don't forget to mark this thread resolved (under Thread Tools).

        Write a Reply...