MSSQL Select column from table

03/19/2010 06:04 da_unknown#1
Hi ,
i have a little problem with mssql , cuz i wanted read out some columns to show in a table with php.
My Question is how i can make a row of the dataset.
I tried it but i see only the same in the table not the next entries of the column.

here a part of the code:

Code:
echo "<center><table border='1'><tr>
	        <td align='center'><font color='#FFFFFF'>Char_no</font></td>
		<td align='center'><font color='#FFFFFF'>wIndex</font></td>
		<td align='center'><font color='#FFFFFF'>Header</font></td>
		<td align='center'><font color='#FFFFFF'>line_no</font></td>
		
	</tr>";


$con = mssql_connect($mssql['host'],$mssql['user'],$mssql['pass']) or die("Connection lost,try it again later.");

$result1 = mssql_query("SELECT character_no FROM character.dbo.user_bag WHERE character_no = 'A09050520000000021'",$con);


while($row1 = mssql_fetch_row($result1)) {
	
	$result2 = mssql_query("SELECT character_no,wIndex,byHeader,line_no FROM character.dbo.user_bag WHERE character_no = 'A09050520000000021' ORDER by line_no DESC",$con);
	$row2 = mssql_fetch_row($result2);

	{

echo "<tr>
<td align='center'><font color='#FFFFFF' size='3' >".$row2[0]."</font></td>
<td align='center'><font color='#FFFFFF' size='3' >".$row2[1]."</font></td>
<td align='center'><font color='#FFFFFF' size='3' >".$row2[2]."</font></td>
<td align='center'><font color='#FFFFFF' size='3' >".$row2[3]."</font></td>
			
		</tr>";

	}

}

echo "</table></center>";
--------------------------------------------------------------
My Results are like this

Char_no wIndex byHeader line_no
1 9901 1 1
1 9901 1 1
1 9901 1 1

Just the same item
it must looks like this that i see all items from a character for example

Char_no wIndex byHeader line_no
1 9901 1 1
1 9902 5 16
1 9903 8 24

I hope anyone can help.

Greetings
dA-uNknOwN
03/19/2010 07:50 Zombe#2
I use my cleaned database, so I don't rly have any characters or items, but try this:

PHP Code:
<?php
echo ("
    <center>
        <table border='1'>
            <tr>
                <td align='center'><font color='#FFFFFF'>Char_no</font></td>
                <td align='center'><font color='#FFFFFF'>wIndex</font></td>
                <td align='center'><font color='#FFFFFF'>Header</font></td>
                <td align='center'><font color='#FFFFFF'>line_no</font></td>    
            </tr>
"
);
$con mssql_connect('host','user','password') or die("Couldn't connect to the database.");
$result mssql_query("SELECT character_no FROM character.dbo.user_bag WHERE character_no = 'A09050520000000021'",$con);
while(
$array mssql_fetch_row($result))
{
    
$result2 mssql_query("SELECT character_no,wIndex,byHeader,line_no FROM character.dbo.user_bag WHERE character_no = 'A09050520000000021' ORDER by line_no DESC",$con);
    while(
$array2 mssql_fetch_row($result2));
    {
        echo (
"<tr>");
        foreach(
$array2 as $row) echo("<td align='center'><font color='#FFFFFF' size='3' >$row</font></td>");
        echo(
"</tr>");
    }
}
echo (
"
        </table>
    </center>"
);
?>
Give it a try.
03/19/2010 08:35 pieter#3
of all else fails u can always go DISTINCT :)

but zombe's sollution should work
03/19/2010 11:14 da_unknown#4
Hi Zombe,
Thanks for your anwser your code looks easier and cleaner.
I got an error with this foreach invalid argument i added before foreach

$array2 = array();

and the error is away but it gives me no results
with

array(1, 2, 3, 4);

i see an empty table.

The solution is near but .. i send you a pm with a testlogin to my database eventually you have time for a new idea :p

Greetings
dA-uNknOwN