Cannot print the data from database in the webpage

From: Date: Sat, 14 Feb 2009 05:05:01 +0000
Subject: Cannot print the data from database in the webpage
Groups: php.db 
Request: Send a blank email to php-db+get-45955@lists.php.net to get a copy of this message
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

« previous php.db (#45955) next »