Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts

    INNER JOIN issue with PHP MSSQL

    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 Code:
    <?php
     
    $sqlconnect
    =mssql_connect($server$username$password);
    $sqldb=mssql_select_db("DATABASE",$sqlconnect);
    ?>
    <?php
    $sqlquery
    ="SELECT * FROM [Tbl-ComputerDetails]";
    $resultsmssql_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);
    ?>
    Last edited by glish_dreams; 12-23-2007 at 01:18 AM.

  • #2
    Regular Coder
    Join Date
    Dec 2005
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 Code:
    <?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";
    $resultsmssql_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);
    ?>
    Last edited by glish_dreams; 12-23-2007 at 01:18 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •