PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
JimiH
Forum Commoner
Posts: 92 Joined: Thu Jun 15, 2006 6:10 am
Post
by JimiH » Mon Dec 04, 2006 9:48 am
Hi
I have this code which displays a particular field ("field1") from a MSSQL database
Code: Select all
<?php
error_reporting(E_ALL);
$server="server";
$username="administrator";
$password="***";
$db = "SQL";
$table = "table";
$sqlconnect=mssql_connect($server, $username, $password);
$sqldb=mssql_select_db($db,$sqlconnect);
$sqlquery="SELECT * FROM $table;";
$results= mssql_query($sqlquery);
while ($row=mssql_fetch_array($results)){
echo $row['field1']."<br>\n";}
mssql_close($sqlconnect);
?>
How do I display all the fields in the DB along with their corresponding data.
Thanks
Geoff
timclaason
Forum Commoner
Posts: 77 Joined: Tue Dec 16, 2003 9:06 am
Location: WI
Post
by timclaason » Mon Dec 04, 2006 11:28 am
I don't think there's a built in variable to output all variables. I think you'll just need to do $row['field1'], $row['field2'], etc.
Unless anyone else knows of any better way to do it.
ok
Forum Contributor
Posts: 393 Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land
Post
by ok » Mon Dec 04, 2006 12:38 pm
Try:
Code: Select all
//...
$results = mssql_query($sqlquery);
$number_of_fields = mssql_num_fields($results);
while($row = mssql_fetch_row($results))
{
for($i = 0; $i < $number_of_fields; $i++)
{
echo mssql_field_name($results, $i);
}
echo "<br />";
for($i = 0; $i < count($row); $i++)
{
echo $row[$i ]." ";
}
echo "<br />";
}
//...
JimiH
Forum Commoner
Posts: 92 Joined: Thu Jun 15, 2006 6:10 am
Post
by JimiH » Tue Dec 05, 2006 5:22 am
Thanks OK
That worked!!!
Geoff