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

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.