samedi 25 juin 2016

turning all id's into a table to its value in another table

i have two tables Table contacts and Table companies. In table contact there's 4 columns called company id(1-4) in these columns there's the company id(s) that the person is associated with. now the problem is that instead of the id i want to be able to display the company name i tried it with the following query but it only gives me values of the last row select * from contact as ct join company as cy1 on cy1.Company_id = ct.Company_id1 join company as cy2 on cy2.Company_id = ct.Company_id2 join company as cy3 on cy3.Company_id = ct.Company_id2 join company as cy4 on cy4.Company_id = ct.Company_id4 $stmt = sqlsrv_query( $conn, $sql , array(), array( "Scrollable" => 'static' ) ); if( $stmt === false) { die( print_r( sqlsrv_errors(), true) ); } $stmtcount = sqlsrv_num_rows($stmt); if ($stmtcount > 0) { while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) { $id = $row['Contact_id']; $fname = $row['Firstname']; $lname = $row['Lastname']; $company1=$row['Company']; $company2=$row['Company']; $company3=$row['Company']; $company4=$row['Company']; echo '<tr>'; echo "<td> <a class='notice' href='details.php?id=" . $id . " '>" .$row['Abbreviation'].'&nbsp'. $row['Firstname'] . "</a> </td>"; echo '<td>'.$lname.'</td>'; echo '<td>'.$company1.'</td>'; echo '<td>'.$company2.'</td>'; echo '<td>'.$company3.'</td>'; echo '<td>'.$company4.'</td>'; echo '</tr>'; the results are as follows result of the query the table structure and here's the database table

Aucun commentaire:

Enregistrer un commentaire