Forum Moderators: coopster

Message Too Old, No Replies

Formatting output from MSSQL

         

xxBHBxx

4:13 pm on Apr 7, 2010 (gmt 0)

10+ Year Member



Hi All,

I need some help or direction on how make this work.

I have created a script to query a mssql db with success, however I am having trouble with the output.

The table structure is not changeable so I need to work with it as is, below is the table structure and some sample data.

RFQINC ROWCOL ROWHEADER COLHEADER VALUE
100010 1 1 Piece Price Piece Price Piece Price
100010 1 2 Piece Price Standard Standard
100010 2 1 110 Piece Price 110
100010 2 2 110 Standard 153.82

The desired output should be as follows

Piece Price Standard
110 153.82

Basically at each change in row number, the result of value(s) from that row would be output to a new line. Current code is below.

<?php

function left($string, $count){return substr($string, 0, $count);};

myServer = "sql";
$myUser = "";
$myPass = "";
$myDB = "db_Live";

$dbhandle = mssql_connect($myServer, $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer");

$selected = mssql_select_db($myDB, $dbhandle) or die("Couldn't open database $myDB");
$query = "SELECT * from SpreadsheetOnSave where rfqinc like '100010'";

$result = mssql_query($query);

while($row = mssql_fetch_array($result))
{
echo "Row: $row[Value]<br>";
echo "<br>";

}

Any help would be greatly appericated.

Thanks

BHB

xxBHBxx

4:20 pm on Apr 7, 2010 (gmt 0)

10+ Year Member



New output table below, separating each column value with single quotations for easier reading.


'RFQINC' 'ROWCOL' 'ROWHEADER' 'COLHEADER' 'VALUE'
'100010' '1' '1' 'Piece Price' 'Piece Price' 'Piece Price'
'100010' '1' '2' 'Piece Price' 'Standard' 'Standard'
'100010' '2' '1' '110' 'Piece Price' '110'
'100010' '2' '2' '110' 'Standard' '153.82'

Pico_Train

4:39 pm on Apr 7, 2010 (gmt 0)

10+ Year Member



Try change this:

while($row = mssql_fetch_array($result))
{
echo "Row: $row[Value]<br>";
echo "<br>";

}

to this

while($row = mssql_fetch_array($result))
{
echo "Row:".$row[Value]."&nbsp;".$row[price]."&nbsp;".$row[standard]."<br><br>";

change Value Price and Standard to the right column names.
}

Pico_Train

4:43 pm on Apr 7, 2010 (gmt 0)

10+ Year Member



sorry this

while($row = mssql_fetch_array($result))
{
echo "Row:".$row[Value]."&nbsp;".$row[price]."&nbsp;".$row[standard]."<br><br>";
}


And then change Value Price and Standard to the right column names.

xxBHBxx

5:38 pm on Apr 7, 2010 (gmt 0)

10+ Year Member



Thanks Pico, I might not be describing what I need properly.

If you look at the table output, there are 6 columns as shown below.

Table Structure - Columns
'RFQINC'
'ROW'
'COL'
'ROWHEADER'- redundant IMO but I didn't create the table
'COLHEADER'- redundant IMO but I didn't create the table
'VALUE'

The data its self are the contents of a spreadsheet if you will, so for example

Row 1, Col 1 contains 'Piece Price'
Row 1, Col 2 contains 'Standard'
Row 2, Col 1 contains '110'
Row 2, Col 2 contains '153.82'

The idea is to basically recreate the spreadsheet in a html table. All data from row 1, would be output to the first row of the table, and the second row and so on.

I hope this more accurately describes the bigger pictures of what I am trying to accomplish.

Thanks again!