⟩ How To Loop through Result Set Objects using mssql_fetch_array()?
If the returning output of a query statement is captured in a result set object, you can use mssql_fetch_array() to loop through each row in the output.
The tutorial PHP script below shows you how to list tables in the database:
<?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: ");
while ($row = mssql_fetch_array($res)) {
print(" ".$row{'name'}." ");
}
mssql_free_result($res);
mssql_close($con);
?>
If you run this script, you will get something like:
User Tables:
ggl_rates
ggl_team
ggl_random
ggl_links_indexed
ggl_links
ggl_links_copy
tipBackup2