iifraz Posted November 11, 2017 Share Posted November 11, 2017 (edited) I have two tables One contains details of employees Second contains details of employee’s Family details The column empid is similar to both table I am trying to display details as for every employee detail from first table as a header and details of employee family details underneath. So for every employee empid it should display the related family details. In the web browser image show the result but not under appropriate header Please can some one help me. Edited November 11, 2017 by iifraz Quote Link to comment Share on other sites More sharing options...
Barand Posted November 11, 2017 Share Posted November 11, 2017 What have you tried so far? Quote Link to comment Share on other sites More sharing options...
iifraz Posted November 11, 2017 Author Share Posted November 11, 2017 What have you tried so far? The result is not displaying underneath the appropriate header Quote Link to comment Share on other sites More sharing options...
AzeS Posted November 11, 2017 Share Posted November 11, 2017 (edited) Try this: $data_set = array('KMP' => array(), 'empid' => array()); while($line = $head->fetch_assoc()) { array_push($data_set['KMP'], "<hr>" . "KMP: " . $line["empid"] . "<hr>"); } while($row = $result->fetch_assoc()) { array_push($data_set['empid'], " EMP ID: " . $row['empid'] . " Full Name: " . $row["fullname"] . " Relship: " . $row['relship'] . "<br>"); } for ($i=0; $i <= count($data_set); $i++) { echo $data_set['KMP'][$i]; echo $data_set['empid'][$i]; } You've tried to put a while loop over another one and expexted a recrusive stacking. Something like that is not possible, because the centred while loop is executed until its condition is met.http://php.net/manual/en/control-structures.while.php Edited November 11, 2017 by AzeS Quote Link to comment Share on other sites More sharing options...
iifraz Posted November 12, 2017 Author Share Posted November 12, 2017 (edited) Try this: $data_set = array('KMP' => array(), 'empid' => array()); while($line = $head->fetch_assoc()) { array_push($data_set['KMP'], "<hr>" . "KMP: " . $line["empid"] . "<hr>"); } while($row = $result->fetch_assoc()) { array_push($data_set['empid'], " EMP ID: " . $row['empid'] . " Full Name: " . $row["fullname"] . " Relship: " . $row['relship'] . "<br>"); } for ($i=0; $i <= count($data_set); $i++) { echo $data_set['KMP'][$i];echo $data_set['empid'][$i];}You've tried to put a while loop over another one and expexted a recrusive stacking. Something like that is not possible, because the centred while loop is executed until its condition is met. http://php.net/manual/en/control-structures.while.php when ever I add a record for a specific empid, the it goes to a new section instead of it being under the specific empid, as attached screenshot, the new record with empid has to be under KMP 177a, instead its under a new KMP. please support Edited November 12, 2017 by iifraz Quote Link to comment Share on other sites More sharing options...
AzeS Posted November 13, 2017 Share Posted November 13, 2017 $row['relship'] => $row['relationship'] I'm sorry, I was a bit lazy to write off all your code and abbreviated here and there; Without insulting: please analyze your code before using it; that was a bit harmless now but it could have been an SE attack so check out the foreign code before using it and please stop taking screenshots and post the code, it is corrosive to write it off permanently; I recommend you to deal more with logical mathematical processes and logical processes before you get to the programming itself. Besides, the server is talking to you and has already pointed out the mistake notice undefied index 'relship' So read, think, write! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.