maliary Posted July 20, 2007 Share Posted July 20, 2007 Hi, I've got 2 tables with the following fields. 1.table A - fields(groupname,name) 2.table B - fields(groupname,values,result) I need to display data from the tables in the following way groupname name values result groupname name values result For every group name i have the name, values and result underneath. How can I do this? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 20, 2007 Share Posted July 20, 2007 SELECT <column_name> FROM <Table1>, <Table2> WHERE (Table1.column = Table2.column) ie SELECT tableB.groupname,tableB.values,tableB.result FROM tableA, tableB WHERE (tableA.groupname= tableB.groupname) Quote Link to comment Share on other sites More sharing options...
dbo Posted July 20, 2007 Share Posted July 20, 2007 SELECT `tableA`.`groupname`, `tableA`.`name`, `tableB`.`values`, `tableB`.`result` FROM `tableA`, `tableB` WHERE `tableA`.`groupname` = `tableB`.`groupname` GROUP BY `tableA`.`groupname`; Quote Link to comment Share on other sites More sharing options...
jvrothjr Posted July 20, 2007 Share Posted July 20, 2007 look into table jion Quote Link to comment Share on other sites More sharing options...
maliary Posted July 20, 2007 Author Share Posted July 20, 2007 SELECT <column_name> FROM <Table1>, <Table2> WHERE (Table1.column = Table2.column) ie SELECT tableB.groupname,tableB.values,tableB.result FROM tableA, tableB WHERE (tableA.groupname= tableB.groupname) the groupname value is being passed from a form. How can you change this query to include that? Quote Link to comment Share on other sites More sharing options...
maliary Posted July 20, 2007 Author Share Posted July 20, 2007 Let me include the unique field, 1.table A - fields(batch,groupname,name) 2.table B - fields(batch,groupname,values,result) I need to display data from the tables in the following way groupname name values result groupname name values result The field batch is unique. The variable $batch is passed through a $_GET to out put the data from the select statement. For every group name i have the name, values and result underneath. How can I do this? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 20, 2007 Share Posted July 20, 2007 try $batch = (int)$_GET['batch ']; $aSQL = "SELECT tableB.groupname,tableB.values,tableB.result FROM tableA, tableB WHERE (tableA.groupname= tableB.groupname) AND tableB.batch = $batch"; i assume the get is batch and the value will be a number ie ?batch=123 Quote Link to comment Share on other sites More sharing options...
maliary Posted July 21, 2007 Author Share Posted July 21, 2007 Yes, It's an int. the display is not good. Man AMOEBIC HAEMOGUTINATION Woman BLOOD GROUP & RHESUS Man BRUCELLA TEST Woman CD4/CD8 Woman this is the display code $echo '<tr >'; $echo '<td> '.$rows['group_id'].' </td>'."\n"; $echo '</tr>'; $echo '<tr >'; $echo '<td> '.$rows['name'].' </td>'."\n"; $echo '<td width="149" valign="top"> '.$rows['normals'].' </td>'."\n"; $echo '<td> '.$rows['msr_unit'].'</td>'."\n"; $echo "<td width=149 valign=top> $rval[$counterup] </td>"; $echo '</tr>'; Quote Link to comment Share on other sites More sharing options...
maliary Posted July 21, 2007 Author Share Posted July 21, 2007 It should be like Man AMOEBIC HAEMOGUTINATION BRUCELLA TEST Woman BLOOD GROUP & RHESUS CD4/CD8 Quote Link to comment Share on other sites More sharing options...
maliary Posted July 21, 2007 Author Share Posted July 21, 2007 Well guys, This sorts that problem out $depts = $db->Execute("SELECT $dbtable.serial_value,$dbtable.type,$dbtable.group_id,$table.name,$table.nr,$table.normals,$table.msr_unit FROM $dbtable,$table WHERE ($table.group_id = $dbtable.group_id) AND $dbtable.job_id = '$batch_nr' ORDER BY group_id ASC"); But there is another problem: serial_value is a string that I am retriving from the database. So where I have 2 group_id's matching say with the man woman groups above, I expect two rows of data however I can only retrive for one row only for the serial value field. why is this? while($rows= $depts->FetchRow()) { echo $rows['serial_value']; } 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.