Jump to content

Help displaying field in table 1 from table 2


enigma1

Recommended Posts

Any help would be appreciated - if you can understand what i've done. I think it's a simple fix but just can't see it. This is my first post so please be gentle.

 

I have 2 tables in mysql, tableA and tableB.

 

TableA has the fields tableA_id and photo

 

TableB has the fields tableB_id, tableA_id and TableA

 

There is a relationship between the 2 tables and it's better shown if i use data.

 

Data in TableA

 

TableA_id

1

2

3

 

photo

pic1

pic2

pic3

 

Data in TableB

 

TableB_id

1

2

3

 

TableA_id

1

2

3

 

TableA

3

2

1

 

I am having trouble displaying the field in photo (TableA) from TableB. This is my php code:

 

$tab_qry = $DB -> query("
            SELECT
                b.*,
                a.photo
                
                                
            FROM
                TableB AS b
                
            LEFT JOIN
                TableA AS a
                
                ON (a.TableA_id = b.TableA_id )
                                
            WHERE
                b.TableB_id = " . $TableB_id
            );
        
        $tab = array();
        
        while($ta = $DB -> fetch_array($tab_qry)){
                    
            $tab[] = $ta;
        }  

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.