Jump to content

Data retrival


maliary

Recommended Posts

 

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?

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

 

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

 

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>';

 

 

 

 

Link to comment
Share on other sites

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'];
}

 

 

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.