Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 来自[SAILING TRIP DETAIL]标准,其中[TRIP NUMBER]=@TripNumber和[SAILING SEQUENCE]=@SegmentNumber 结束 结束 去_Php_Sqlsrv - Fatal编程技术网

Php 来自[SAILING TRIP DETAIL]标准,其中[TRIP NUMBER]=@TripNumber和[SAILING SEQUENCE]=@SegmentNumber 结束 结束 去

Php 来自[SAILING TRIP DETAIL]标准,其中[TRIP NUMBER]=@TripNumber和[SAILING SEQUENCE]=@SegmentNumber 结束 结束 去,php,sqlsrv,Php,Sqlsrv,我不确定我还能在这里补充什么。Stackoverflow不允许我发布,因为它不喜欢文本与代码的比率:|这就是为什么:)一个可能的解决方案是将SET NOCOUNT放在存储过程的第一行,以防止返回受t-SQL语句影响的行数作为结果集的一部分。这可能会有帮助。确实是这样,谢谢! <?php header("Access-Control-Allow-Origin: *"); $serverName = "tcp:example.database.windows.net,1433"; $conn

我不确定我还能在这里补充什么。Stackoverflow不允许我发布,因为它不喜欢文本与代码的比率:|这就是为什么:)

一个可能的解决方案是将
SET NOCOUNT放在存储过程的第一行,以防止返回受t-SQL语句影响的行数作为结果集的一部分。这可能会有帮助。确实是这样,谢谢!
<?php
header("Access-Control-Allow-Origin: *");

$serverName = "tcp:example.database.windows.net,1433";
$connectionInfo = array( "Database"=>"Whitecap", "UID"=>"example", "PWD"=>"example", "CharacterSet"=>"UTF-8");
$conn = sqlsrv_connect( $serverName, $connectionInfo );


$arg1 = 'ES04';
$arg2 = '1';
$output = '';
$call = "{CALL uspGetSegmentInfo (?,?) }";
$params = [ 
  [$arg1, SQLSRV_PARAM_IN],
  [$arg2, SQLSRV_PARAM_IN],
  [&$output, SQLSRV_PARAM_OUT],
];

$result = sqlsrv_query($conn, $call, $params);
$array = [];

while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_NUMERIC)) {
  $obj = new stdClass;
  $obj->id = $row[1];
  $obj->name = $row[0];

  $array[] = $obj;
}

echo json_encode($array);
?>
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[uspGetSegmentInfo] @TripNumber varchar(10), @SegmentNumber int
AS
BEGIN
    -- Segment data
    declare @Segments Table (Sequence int, [Segment Type] varchar(20))
    declare @SegmentType varchar(20)

    insert @Segments exec uspGetTripSegments @TripNumber
    select @SegmentType = [Segment Type] from @Segments where Sequence = @SegmentNumber

    -- Departure Port
    IF @SegmentType = 'Departure Port'
        BEGIN        
            select (select [port name] from [PORT DETAIL] pd where pd.[PORT ID] = ptd.[PORT ID]) as 'PORT NAME', 
            (select dd.[dock name] from [DOCK DETAIL] dd where dd.[DOCK ID] = ptd.[DOCK ID]) as 'DOCK NAME' 
            from [PORT TRIP DETAIL] ptd where [TRIP NUMBER] = @TripNumber and [PORT SEQUENCE] = @SegmentNumber
        END
    -- Load/Discharge Port (INCOMPLETE)
    ELSE IF @SegmentType = 'Load Port' OR @SegmentType = 'Discharge Port'
        BEGIN
            declare @CargoPortInfo table ([PORT NAME] varchar(50),[DOCK NAME] varchar(50),CUSTOMER varchar(50),[CARGO TYPE] varchar(50),[CARGO SUB TYPE] varchar(50),TONNAGE varchar(20),LAYTIME VARCHAR(10),[EXPECTED DURATION] varchar(10))
            declare @NumberCargos int
            declare @PortName varchar(50)
            declare @DockName varchar(50)
            declare @Customer varchar(50)
            declare @CargoType varchar(50)
            declare @CargoSubType varchar(50)
            declare @Tonnage varchar(20)
            declare @Laytime varchar (10)
            declare @Duration varchar(10)
            declare @CurrentCargoID int
            declare @i int

            -- Get number of cargos for this port
            select @NumberCargos = count(distinct [cargo detail id]) from [cargo event detail] where [TRIP NUMBER] = @TripNumber and [CARGO SEQUENCE] = @SegmentNumber

            -- Loop through cargos
            set @i = 1
            while @i < (@NumberCargos + 1)
                begin
                    select @CurrentCargoID = [cargo detail id] from [cargo event detail] where [TRIP NUMBER] = @TripNumber and [CARGO SEQUENCE] = @SegmentNumber and [SOURCE CARGO ID] = @i

                    -- Port Name
                    select @PortName = (select [port name] from [PORT DETAIL] pd where pd.[PORT ID] = ptd.[PORT ID]) from [PORT TRIP DETAIL] ptd where [TRIP NUMBER] = @TripNumber and [PORT SEQUENCE] = @SegmentNumber

                    -- Dock Name
                    select @DockName = (select dd.[dock name] from [DOCK DETAIL] dd where dd.[DOCK ID] = ptd.[DOCK ID]) from [PORT TRIP DETAIL] ptd where [TRIP NUMBER] = @TripNumber and [PORT SEQUENCE] = @SegmentNumber

                    -- Customer
                    select @Customer = (select cd.[CUSTOMER NAME] from [CUSTOMER DETAIL] cd where cd.[CUSTOMER ID] = crd.[CUSTOMER ID]) from [CARGO DETAIL] crd where crd.[cargo detail id] = @CurrentCargoID

                    -- Cargo type
                    select @CargoType = (select ct.[CARGO TYPE NAME] from [CARGO TYPE] ct where ct.[CARGO TYPE ID] = crd.[CARGO TYPE ID]) from [CARGO DETAIL] crd where crd.[cargo detail id] = @CurrentCargoID

                    -- Cargo sub type
                    select @CargoSubType = (select cst.[CARGO SUB TYPE NAME] from [CARGO SUB TYPE] cst where cst.[CARGO SUB TYPE ID] = crd.[CARGO SUB TYPE ID]) from [CARGO DETAIL] crd where crd.[cargo detail id] = @CurrentCargoID

                    -- Tonnage
                    select @Tonnage = concat(format(convert(decimal(10,2),[EXPECTED TONNAGE]),'#,#'),' ',[EXPECTED TONNAGE UNITS]) from [CARGO EVENT DETAIL] ced where ced.[TRIP NUMBER] = @TripNumber and ced.[CARGO SEQUENCE] = @SegmentNumber and ced.[CARGO DETAIL ID] = @CurrentCargoID

                    -- Laytime
                    select @Laytime = concat([LAYTIME RATE],' ',[LAYTIME RATE UNITS]) from [CARGO EVENT DETAIL] ced where ced.[TRIP NUMBER] = @TripNumber and ced.[CARGO SEQUENCE] = @SegmentNumber and ced.[CARGO DETAIL ID] = @CurrentCargoID

                    -- Get cargo laytime allowance in hours
                    select @Duration = convert(decimal(10,5),[cargo load time]) from [CARGO EVENT DETAIL] ced where ced.[TRIP NUMBER] = @TripNumber and ced.[CARGO SEQUENCE] = @SegmentNumber and ced.[CARGO DETAIL ID] = @CurrentCargoID

                    -- Format duration
                    set @Duration = dbo.getFormattedDuration(@Duration,'H')

                    insert into @CargoPortInfo values (@PortName,@DockName,@Customer,@CargoType,@CargoSubType,@Tonnage,@Laytime,@Duration)

                    set @i = @i + 1
                end

                -- Return merged list
                select * from @CargoPortInfo
        END
    -- Sailing Segment
    ELSE
        BEGIN        
            -- Grab total sailing time in minutes
            select @Duration = sum([standard time minute]) from [SAILING SEGMENT DETAIL] ssd where ssd.[SAILING TRIP ID] = (select [sailing trip id] from [sailing trip detail] where [TRIP NUMBER] = @TripNumber and [SAILING SEQUENCE] = @SegmentNumber)

            -- Convert to display format
            set @Duration = dbo.getFormattedDuration(@Duration,'M')

            select (select [port name] from [PORT DETAIL] pd where pd.[PORT ID] = std.[starting PORT ID]) as 'START PORT', 
            (select pd.[port name] from [port DETAIL] pd where pd.[PORT ID] = std.[ending port ID]) as 'END PORT',
            (select @Duration) as 'EXPECTED DURATION'
            from [SAILING TRIP DETAIL] std where [TRIP NUMBER] = @TripNumber and [SAILING SEQUENCE] = @SegmentNumber
        END
END

GO