Search

Sunday, July 31, 2016

Dynamic php code to get database fields in sql server

Here is small code snippet to display php fields dynamically:

page.php

<?php
....
....
$sql = "SELECT * FROM xyz where student1 ='$user1'";
$stmt = sqlsrv_query($conn, $sql);

                 if( $stmt === false ) {
die( '<pre>'.print_r( sqlsrv_errors(), true).'</pre>' );
};
if( sqlsrv_fetch($stmt) === false ) {
die( '<pre>'.print_r( sqlsrv_errors(), true).'</pre>' );
};

....
....
?>


page1.php

<?php
global $stmt;
col4=;
echo col4;
?>

No comments:

Post a Comment