...

View Full Version : INNER JOIN issue with PHP MSSQL



glish_dreams
12-22-2007, 08:38 PM
Im needing to select multible tables in one report.
Below is the current Pull of data,

Issues at hand. This is a MS SQL database, that is ran mainly by an Access program. So I cant rename anything, but luckly all relations are set. MAIN issue. The tables are named with a - Tbl-*****

pcmodel, phnname, and cubename, are all just IDs that Access would pull the inform but 3 diff tables.

I need a php report to do just that. But im stuck...



<?php

$sqlconnect=mssql_connect($server, $username, $password);
$sqldb=mssql_select_db("DATABASE",$sqlconnect);
?>
<?php
$sqlquery="SELECT * FROM [Tbl-ComputerDetails]";
$results= mssql_query($sqlquery);
while ($row=mssql_fetch_array($results)){
$pcid=$row['PCID'];
$pcmodel=$row['PCModel'];
$srvtag=$row['SrvTag'];
$computername=$row['ComputerName'];

?>
<?php
echo"$pcid $pcmodel $srvtag $computername <br>";
?>
<?php }
mssql_close($sqlconnect);
?>

glish_dreams
12-22-2007, 10:06 PM
OK so i was putting my test in fieldname.table not table.field.. So I got a two table statement to work perfect.. Now on to add the other two..


<?php

$sqlconnect=mssql_connect($server, $username, $password);
$sqldb=mssql_select_db("DATABASE",$sqlconnect);
?>
<?php
$sqlquery="SELECT [Tbl-ComputerDetails].*, [Tbl-PCModels].* FROM [Tbl-ComputerDetails] INNER JOIN [Tbl-PCModels] ON [Tbl-ComputerDetails].PCModel = [Tbl-PCModels].PCModelID";
$results= mssql_query($sqlquery);
while ($row=mssql_fetch_array($results)){
$pcid=$row['PCID'];
$pcmodelid=$row['PCModel'];
$srvtag=$row['SrvTag'];
$computername=$row['ComputerName'];

?>
<?php
echo"$pcid $pcmodelid $srvtag $computername<br>";
?>
<?php }
mssql_close($sqlconnect);
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum