Jump to content

PHP list the data from tables from MySQL in a classified manner


iifraz

Recommended Posts

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.

post-206176-0-36021200-1510437934_thumb.jpeg

post-206176-0-16923500-1510437953_thumb.jpeg

Edited by iifraz
Link to comment
Share on other sites

 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 by AzeS
Link to comment
Share on other sites

&nbsp;

&nbsp;Try this:

$data_set = array('KMP' =&gt; array(), 'empid' =&gt; array());		while($line = $head-&gt;fetch_assoc()) {	array_push($data_set['KMP'], "&lt;hr&gt;" . "KMP: " . $line["empid"] . "&lt;hr&gt;");	}		while($row = $result-&gt;fetch_assoc()) {	array_push($data_set['empid'], " EMP ID: " . $row['empid'] . " Full Name: " . $row["fullname"] . " Relship: " . $row['relship'] . "&lt;br&gt;"); 	} for ($i=0; $i &lt;= count($data_set); $i++) {&nbsp;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

&nbsp;

 

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

post-206176-32150_thumb.png

post-206176-0-88823700-1510484545_thumb.png

Edited by iifraz
Link to comment
Share on other sites

$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! :D

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.