Cannot print the data from database in the webpage
am 14.02.2009 06:05:01 von Sashikanth Gurram
--------------010607000301050804050105
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
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 "
\n
$building | \n
$parking_lot | \n
$month | \n
$day | \n
$occupancy | \n
$empty_spaces | \n
$special_days | \n
\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
// 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 "
";
echo "Query sent successfully";
}
echo "
";
echo " OCCUPANCY ";
echo "
";
echo "
|
";
while ($row=mysqli_fetch_array($data))
{
extract($row);
echo "\n
$building | \n
$parking_lot | \n
$month | \n
$day | \n
$occupancy | \n
$empty_spaces | \n
$special_days | \n
\n";
echo "
|
\n";
}
echo "
\n";
?>
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sashikanth Gurram
Graduate Research Assistant
Department of Civil and Environmental Engineering
Virginia Tech
Blacksburg, VA 24060, USA
--------------010607000301050804050105
Content-Type: text/plain; charset=us-ascii
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--------------010607000301050804050105--
Re: Cannot print the data from database in the webpage
am 14.02.2009 06:52:21 von Patrick Price
--0016e6433f3897e4e90462da8e03
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
I believe your problem is that the mysqli_fetch_array function on line 39
returns an enumerated array and the extract function on line 41 takes the
values in an array and assigns it to an associative array based on the
keys. Since the keys in an enumerated array are numbers, those are the
variable names. I believe you will have an easier time if you do the
following:
while ($row=mysqli_fetch_array($data))
{
$building = $row[0];
$parking_lot = $row[1];
$month = $row[2];
$day = $row[3];
$occupancy = $row[4];
$empty_spaces = $row[5];
$special_days = $row[6];
echo "
\n
$building | \n
$parking_lot | \n
$month | \n $day | \n
$occupancy | \n
$empty_spaces | \n
$special_days | \n
\n";
echo "
|
\n";
}
Now it is important in the order with which the fields are returned from the
database since that will affect the row values when you are assigning them
to variables (ie- if the day is returned first in the array it should be "
$day = $row[0]" )
Hope that helps
Thanks
patrick
Sent from: Decatur Ga United States.
On Sat, Feb 14, 2009 at 12:05 AM, Sashikanth Gurram wrote:
> 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 "\n
> $building | \n
> $parking_lot | \n $month | \n
> $day | \n
> $occupancy | \n
> $empty_spaces | \n
> $special_days | \n
>
\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
>
>
>
> // 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 "
";
> echo "Query sent successfully";
> }
>
>
> echo "
";
> echo " OCCUPANCY ";
> echo "
";
> echo "
|
";
> while ($row=mysqli_fetch_array($data))
> {
> extract($row);
> echo "\n
> $building | \n
> $parking_lot | \n
> $month | \n $day | \n
> $occupancy | \n
> $empty_spaces | \n
> $special_days | \n
>
\n";
> echo "
|
\n";
> }
> echo "
\n";
>
>
> ?>
>
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Sashikanth Gurram
> Graduate Research Assistant
> Department of Civil and Environmental Engineering
> Virginia Tech
> Blacksburg, VA 24060, USA
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--0016e6433f3897e4e90462da8e03--
RE: Cannot print the data from database in the webpage
am 14.02.2009 14:46:48 von Chris Verges
------_=_NextPart_001_01C98EAA.CF0D0EB6
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
You may also want to look into the heredoc string literals. It may or =
may not help you with some of these longer "echo" commands. =
http://www.tizag.com/phpT/strings.php has a good explanation, and of =
course the bible is at =
http://us2.php.net/manual/en/language.types.string.php#langu age.types.str=
ing.syntax.heredoc.
Thanks,
Chris
-----Original Message-----
From: Patrick Price [mailto:superpatty@gmail.com]
Sent: Fri 2/13/2009 9:52 PM
To: Sashikanth Gurram
Cc: php-db@lists.php.net
Subject: Re: [PHP-DB] Cannot print the data from database in the webpage
=20
I believe your problem is that the mysqli_fetch_array function on line =
39
returns an enumerated array and the extract function on line 41 takes =
the
values in an array and assigns it to an associative array based on the
keys. Since the keys in an enumerated array are numbers, those are the
variable names. I believe you will have an easier time if you do the
following:
while ($row=3Dmysqli_fetch_array($data))
{
$building =3D $row[0];
$parking_lot =3D $row[1];
$month =3D $row[2];
$day =3D $row[3];
$occupancy =3D $row[4];
$empty_spaces =3D $row[5];
$special_days =3D $row[6];
echo "
\n
$building | \n
$parking_lot | \n
$month | \n $day | \n
$occupancy | \n
$empty_spaces | \n
$special_days | \n
\n";
echo "
|
\n";
}
Now it is important in the order with which the fields are returned from =
the
database since that will affect the row values when you are assigning =
them
to variables (ie- if the day is returned first in the array it should be =
"
$day =3D $row[0]" )
Hope that helps
Thanks
patrick
Sent from: Decatur Ga United States.
On Sat, Feb 14, 2009 at 12:05 AM, Sashikanth Gurram =
wrote:
> 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 "\n
> $building | \n
> $parking_lot | \n =
$month | \n
> $day | \n
> $occupancy | \n
> $empty_spaces | \n
> $special_days | \n
>
\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
>
>
>
> // Connects to your Database
> $host=3D"******";
> $user=3D"******";
> $password=3D"******";
> $dbname=3D"******";
> $cxn=3Dmysqli_connect($host, $user, $password, $dbname) ;
> if (!$cxn=3Dmysqli_connect($host, $user, $password, $dbname))
> {
> $error=3Dmysqli_error($cxn);
> echo "$error";
> die();
> }
> else
> {
> echo "Connection established successfully";
> }
>
> $sql=3D"SELECT * FROM occupancy";
> $data =3D mysqli_query($cxn,$sql);
> if (!$data=3Dmysqli_query($cxn,$sql))
> {
> $error=3Dmysqli_error($cxn);
> echo "$error";
> die();
> }
> else
> {
> echo "
";
> echo "Query sent successfully";
> }
>
>
> echo "
";
> echo " OCCUPANCY ";
> echo "
";
> echo "
|
";
> while ($row=3Dmysqli_fetch_array($data))
> {
> extract($row);
> echo "\n
> $building | \n
> $parking_lot | \n
> $month | \n $day | \n
> $occupancy | \n
> $empty_spaces | \n
> $special_days | \n
>
\n";
> echo "
|
\n";
> }
> echo "
\n";
>
>
> ?>
>
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Sashikanth Gurram
> Graduate Research Assistant
> Department of Civil and Environmental Engineering
> Virginia Tech
> Blacksburg, VA 24060, USA
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
------_=_NextPart_001_01C98EAA.CF0D0EB6--