"while" not looping

So my code does not keep looping with “while”. Is it because of while inside while? if there is only one entry in the db it works fine but when there are 2 or more entries in the database it will not show anything but the first entry. what am I doing wrong? Here is the section of code after my php dropdown box. that part works fine. this is the section with issues. what can i do? Thanks for helping I am total noob!

$sel_id= mysql_query("select master_id from master_family where family_id = '$_POST[fam_id]'");
$s_id= mysql_fetch_row($sel_id);
$num=mysql_num_rows($sel_id);
$i=0;

while ($i < $num) {


$get_master = "select concat_ws(' ', f_name, l_name) as display_name
	from master_name where id= '$s_id[0]'";
$get_master_res = mysql_query($get_master);
$display_name = stripslashes(mysql_result($get_master_res, 0, 'display_name'));

$display_block = "<h1>Showing Record for $display_name</h1>";
	

$get_spouse = "select s_f_name, s_l_name from spouse_name where
	master_id = '$s_id[0]'";
$get_spouse_res = mysql_query($get_spouse);

if (mysql_num_rows($get_spouse_res) > 0) {

	$display_block .= "<p><strong>Spouse Name:</strong><br>
	<ul>";
	
	while ($spouse_info = mysql_fetch_array($get_spouse_res)) {
		$s_f_name = $spouse_info[s_f_name];
		$s_l_name = $spouse_info[s_l_name];
		
		$display_block .= "<li>$s_f_name $s_l_name";
	}
	
	$display_block .= "</ul>";
}

$get_child = "select c_f_name, c_l_name from child_name where
	master_id = '$s_id[0]'";
$get_child_res = mysql_query($get_child);

if (mysql_num_rows($get_child_res) > 0) {

	$display_block .= "<p><strong>Children Names:</strong><br>
	<ul>";
	
	while ($child_info = mysql_fetch_array($get_child_res)) {
		$c_f_name = $child_info[c_f_name];
		$c_l_name = $child_info[c_l_name];
		
		$display_block .= "<li>$c_f_name $c_l_name";
	}
	
	$display_block .= "</ul>";
}

$get_addresses = "select address, city, state, zipcode, type
	from address where master_id = '$s_id[0]'";
$get_addresses_res = mysql_query($get_addresses);

if (mysql_num_rows($get_addresses_res) > 0) {

	$display_block .= "<p><strong>Address:</strong><br>
	<ul>";
	
	while ($add_info = mysql_fetch_array($get_addresses_res)) {
		$address = $add_info[address];
		$city = $add_info[city];
		$state = $add_info[state];
		$zipcode = $add_info[zipcode];
		
		$display_block .= "<li>$address $city $state $zipcode";
	}
	
	$display_block .= "</ul>";
}

$get_tel = "select m_telephone, m_tel_type from master_telephone where
	master_id = '$s_id[0]'";
$get_tel_res = mysql_query($get_tel);

if (mysql_num_rows($get_tel_res) > 0) {

	$display_block .= "<p><strong>$display_name Telephone:</strong><br>
	<ul>";
	
	while ($tel_info = mysql_fetch_array($get_tel_res)) {
		$tel_number = $tel_info[m_telephone];
		$tel_type = $tel_info[m_tel_type];
		
		$display_block .= "<li>$tel_number ($tel_type)";
	}
	
	$display_block .= "</ul>";
}

$get_s_tel = "select s_telephone from spouse_name where
	master_id = '$s_id[0]'";
$get_s_tel_res = mysql_query($get_s_tel);

if (mysql_num_rows($get_s_tel_res) > 0) {

	$display_block .= "<p><strong>$s_f_name Telephone:</strong><br>
	<ul>";
	
	while ($s_tel_info = mysql_fetch_array($get_s_tel_res)) {
		$s_tel_number = $s_tel_info[s_telephone];
		
		$display_block .= "<li>$s_tel_number";
	}
	
	$display_block .= "</ul>";
}

$get_c_tel = "select c_f_name,c_telephone from child_name where
	master_id = '$s_id[0]'";
$get_c_tel_res = mysql_query($get_c_tel);

if (mysql_num_rows($get_c_tel_res) > 0) {

	$display_block .= "<p><strong>Children Telephone:</strong><br>
	<ul>";
	
	while ($c_tel_info = mysql_fetch_array($get_c_tel_res)) {
		$c_tel_number = $c_tel_info[c_telephone];
		$c_first_name = $c_tel_info[c_f_name];
		
		$display_block .= "<li>$c_first_name - $c_tel_number";
	}
	
	$display_block .= "</ul>";
}

$get_fax = "select fax_number from fax where
	master_id = '$s_id[0]'";
$get_fax_res = mysql_query($get_fax);

if (mysql_num_rows($get_fax_res) >0) {

	$display_block .= "<p><strong>Fax:</strong><br>
	<ul>";
	
while ($fax_info = mysql_fetch_array($get_fax_res)) {
	$fax_number = $fax_info[fax_number];
	
	$display_block .= "<li>$fax_number";
}

$display_block .= "</ul>";
}

$get_m_email = "select m_email from master_name where
	id = '$s_id[0]'";
$get_m_email_res = mysql_query($get_m_email);

if (mysql_num_rows($get_m_email_res) > 0) {

	$display_block .= "<p><strong>$display_name Email:</strong><br>
	<ul>";
	
while ($m_email_info = mysql_fetch_array($get_m_email_res)) {
	$m_email = $m_email_info[m_email];
	
	$display_block .= "<li>$m_email";
}

$display_block .= "</ul>";
}

$get_s_email = "select s_email from spouse_name where
	master_id = '$s_id[0]'";
$get_s_email_res = mysql_query($get_s_email);

if (mysql_num_rows($get_s_email_res) > 0) {

	$display_block .= "<p><strong>$s_f_name Email:</strong><br>
	<ul>";
	
while ($s_email_info = mysql_fetch_array($get_s_email_res)) {
	$s_email = $s_email_info[s_email];
	
	$display_block .= "<li>$s_email";
}

$display_block .= "</ul>";
}

$get_notes = "select note from personal_notes where
	master_id = '$s_id[0]'";
$get_notes_res = mysql_query($get_notes);

if (mysql_num_rows($get_notes_res) == 1) {
	$note = nl2br(stripslashes(mysql_result($get_notes_res,0,'note')));

	$display_block .= "<p><strong>Personal Notes:</strong><br>$note";
}
$i++;
}

$display_block .= "<p align=center>
	<a href=\"addentry.php?master_id=$_POST[sel_id]\">add info</a> ...
	<a href=\"$_SERVER[PHP_SELF]\">select another</a> ... 
	<a href=\"addentry.php\">add new contact</a> ... 
	<a href=\"delentry.php\">delete entry</a></p>";

}
?>

My Records <? print $display_block; ?>

probably because, the incrementation of $i is happening inside two blocks…

$i++;
}

instead of this, try the following

}
$i++;

i mean the inrement is happening inside another block instead of happening in the main while block.

Sponsor our Newsletter | Privacy Policy | Terms of Service