MS SQL Server Concepts and Programming Question:
Download Questions PDF

How To Retrieve Field Values using mssql_result()?

MS SQL Server Interview Question
MS SQL Server Interview Question

Answer:

Once the result set is captured in an object, you can think of it as a "table" with rows and columns (fields). You can use mssql_result() to retrieve the value of any given row and column (field) with this formats:

$value = mssql_result($res, $row, $column);
#- $row is the row number, starting with 0
#- $column is the column number, starting with 0

The tutorial PHP script below shows you how to list tables in the database with multiple field values:

<?php
$con = mssql_connect('LOCALHOST','sa','GlobalGuideLine');
mssql_select_db('GlobalGuideLineDatabase', $con);

$sql = "SELECT * FROM sys.objects"
. " WHERE type_desc='USER_TABLE'";
$res = mssql_query($sql, $con);
print("User Tables: ");
for ($i=0; $i

If you run this script, you will get something like:

User Tables:
ggl_rates, 85575343, USER_TABLE
ggl_team, 165575628, USER_TABLE
ggl_random, 821577965, USER_TABLE
ggl_links_indexed, 1061578820, USER_TABLE
ggl_links, 1093578934, USER_TABLE
ggl_links_copy, 1253579504, USER_TABLE
tipBackup2, 2121058592, USER_TABLE

Download MS SQL Server Interview Questions And Answers PDF

Previous QuestionNext Question
How To Loop through Result Set Objects using mssql_fetch_array()?How To List All Field Names in the Result Set using mssql_field_name()?