Cannot print the data from database in the webpage

[email protected] (Sashikanth Gurram)
Newsgroups php.db
Message-ID <[email protected]>
Hi  all,

I am trying to run a query to retrieve data from mysql database and 
display it in a webpage in a table. The query is running fine, but the 
the data is not appearing on the webpage. All I see is a webpage with 
few empty cells. 

The echo command starting from line 42 is something like this
*echo "<tr>\n
            <td>$building</td>\n
            <td>$parking_lot</td>\n               
            <td>$month</td>\n   
            <td>$day</td>\n
            <td>$occupancy</td>\n
            <td>$empty_spaces</td>\n         
            <td>$special_days</td>\n
            </tr>\n";*

The variables I have used here ie., $building, $parking_lot etc are 
nothing but the column names in the mysql database ie., building, 
parking_lot etc. I hope I did not mess up in that sense. But, I do not 
know the reason for the non appearance of the data.

I am posting the whole code below. Also I am attaching a screenshot of 
the display in the webpage. If anyone has any answer please let me know.

Thanks
Sashi

<?php

// Connects to your Database
$host="******";
$user="******";
$password="******";
$dbname="******";
$cxn=mysqli_connect($host, $user, $password, $dbname) ;
if (!$cxn=mysqli_connect($host, $user, $password, $dbname))
    {
        $error=mysqli_error($cxn);
        echo "$error";
        die();
    }
else
    {
        echo "Connection established successfully";
    }
 
$sql="SELECT * FROM occupancy";
$data = mysqli_query($cxn,$sql);
if (!$data=mysqli_query($cxn,$sql))
    {
        $error=mysqli_error($cxn);
        echo "$error";
        die();
    }
else
    {
        echo "<br>";
        echo "Query sent successfully";
    }


echo "<br>";
echo "<h1> OCCUPANCY <h1>";
echo "<table cellspacing='0'>";
echo "<tr><td colspan='7'><hr /></td></tr>";
while ($row=mysqli_fetch_array($data))
    {
        extract($row);
        echo "<tr>\n
              <td>$building</td>\n
              <td>$parking_lot</td>\n                 
              <td>$month</td>\n  
              <td>$day</td>\n
              <td>$occupancy</td>\n
              <td>$empty_spaces</td>\n           
              <td>$special_days</td>\n
              </tr>\n";
        echo "<tr><td colspan='7'><hr /></td></tr>\n";
    }
    echo "</table>\n";


?>

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sashikanth Gurram
Graduate Research Assistant
Department of Civil and Environmental Engineering
Virginia Tech
Blacksburg, VA 24060, USA
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.