note 87721 added to function.mssql-num-fields
| From: | newyorkcityboy87 at yahoo dot com | Date: | Thu, 18 Dec 2008 09:31:43 +0000 |
| Subject: | note 87721 added to function.mssql-num-fields | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-148295@lists.php.net to get a copy of this message | ||
The example here is wrong or thats what i found out it should be done like this
<?php
// Connect to MSSQL
$link = mssql_connect('KALLESPC\SQLEXPRESS', 'sa', 'phpfi');
mssql_select_db('php', $link);
// Select some data from our database
$data = mssql_query('SELECT [name], [age] FROM [php].[dbo].[persons]');
// Construct a table
echo '<table border="1">';
$header = false;
// Iterate through returned results
while($row = mssql_fetch_array($data))
{
// Build the table header
if(!$header)
{
//echo '<thead>';
echo '<tr>';
/*code before
for($i = 1; ($i + 1) <= mssql_num_fields($data); ++$i)
{
echo '<td>' . ucfirst($row[$i]) . '</td>';
}
*/
//code now
for($i = 1; ($i + 1) <= mssql_num_fields($data); ++$i)
{
echo '<td>' . ucfirst(mssql_fetch_field($data,$i)->name) .
'</td>';
}
echo '</tr>';
//echo '</thead>';
echo '<tbody>';
$header = true;
}
// Build the row
echo '<tr>';
foreach($row as $value)
{
echo '<td>' . $value . '</td>';
}
echo '</tr>';
}
// Close table
echo '</tbody>';
echo '</table>';
// Clean up
mssql_free_result($data);
mssql_close($link);
?>
----
Server IP: 69.147.83.197
Probable Submitter: 213.217.230.106 (proxied: 213.217.230.106)
----
Manual Page -- http://www.php.net/manual/en/function.mssql-num-fields.php
Edit -- https://master.php.net/note/edit/87721
Del: integrated -- https://master.php.net/note/delete/87721/integrated
Del: useless -- https://master.php.net/note/delete/87721/useless
Del: bad code -- https://master.php.net/note/delete/87721/bad+code
Del: spam -- https://master.php.net/note/delete/87721/spam
Del: non-english -- https://master.php.net/note/delete/87721/non-english
Del: in docs -- https://master.php.net/note/delete/87721/in+docs
Del: other reasons-- https://master.php.net/note/delete/87721
Reject -- https://master.php.net/note/reject/87721
Search -- https://master.php.net/manage/user-notes.php