0

My current connection and echo code is as follwed:

 <?php
            $myServer = "Server_Name";
            $myUser = "User";
            $myPass = "Pass";
            $myDB = "DB_Name"; 

        //connection to the database
            $dbhandle = sqlsrv_connect($myServer, $myUser, $myPass)
                or die("Couldn't connect to SQL Server on $myServer"); 

        //select a database to work with
            $selected = mssql_select_db($myDB, $dbhandle)
                or die("Couldn't open database $myDB"); 

        //declare the SQL statement that will query the database
            $query = "SELECT col1, col3, col4, col5, col6,  ";
            $query .= "FROM dbo.Quotes ";

        //execute the SQL query and return records
            $result = mssql_query($query)
                or die('A error occured: ' . mysql_error());

        //Show results in table

        $o = '<table id="myTable">
                <thead>
                <tr>
                <th>Col 1</th>
                <th>Col 2</th>
                <th>Col 2</th>
                <th>Col 2</th>
                <th>Col 2</th>

                </tr>
                </thead><tbody>';

               while ( $record = mssql_fetch_array($result) )
         {
             $o .= '<tr><td>'.$record ['col1'].'</td><td>'.$record ['col3'].'</td></tr>' .$record ['col4'].'</td></tr>' .$record ['col5'].'</td></tr>' .$record ['col6'].'</td></tr>';
         } 




        //free result set memory
            mssql_free_result($result);

        //close the connection
            mssql_close($dbhandle);
        ?>

Edited by Jack_14

2
Contributors
7
Replies
30
Views
2 Years
Discussion Span
Last Post by pritaeas
0

I seem to through errors when I launch the code It doesn't go into the table it should and instead looks like this on the webpage:

Col 1 Col 2 Col 2 Col 2 Col 2 '; while ( $record = mssql_fetch_array($result) ) { $o .= ''.$record ['col1'].''.$record ['col3'].'' .$record ['col4'].'' .$record ['col5'].'' .$record ['col6'].''; } //free result set memory mssql_free_result($result); //close the connection mssql_close($dbhandle); ?>

Edited by Jack_14

0

On line 16 remove the comma at the end (after col6). Although that should end the code on line 20 with an error instead of rendering what you are showing.

0

Although that should end the code on line 20 with an error instead of rendering what you are showing.

Its still showing the same message, with updated code:

   <?php
                $myServer = "Server_Name";
                $myUser = "User";
                $myPass = "PassWord";
                $myDB = "Db_Name"; 

            //connection to the database
                $dbhandle = sqlsrv_connect($myServer, $myUser, $myPass)
                    or die("Couldn't connect to SQL Server on $myServer"); 

            //select a database to work with
                $selected = mssql_select_db($myDB, $dbhandle)
                    or die("Couldn't open database $myDB"); 

            //declare the SQL statement that will query the database
                $query = "SELECT col1, col3, col4, col5, col6  ";
                $query .= "FROM dbo.Quotes ";

            //execute the SQL query and return records
                $result = mssql_query($query)
                    or die('A error occured: ' . mysql_error());

            //Show results in table

            $o = '<table id="myTable">
                    <thead>
                    <tr>
                    <th>Col 1</th>
                    <th>Col 2</th>
                    <th>Col 2</th>
                    <th>Col 2</th>
                    <th>Col 2</th>

                    </tr>
                    </thead><tbody>';

                   while ( $record = mssql_fetch_array($result) )
             {
                 $o .= '<tr><td>'.$record ['col1'].'</td><td>'.$record ['col3'].'</td></tr>' .$record ['col4'].'</td></tr>' .$record ['col5'].'</td></tr>' .$record ['col6'].'</td></tr>';
             } 




            //free result set memory
                mssql_free_result($result);

            //close the connection
                mssql_close($dbhandle);
            ?>

Edited by Jack_14

0

UPDATE It now doesn't display anything, no errors no code!

Plus it doesn't display a table or anything the page returns blank.

Edited by Jack_14

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.