Forum Moderators: coopster

Message Too Old, No Replies

Select Query not working

Not sure if problem is with database or PHP script?

         

erdy

11:12 pm on Mar 16, 2008 (gmt 0)

10+ Year Member



Hi,

I am very new to PHP/MySQL.
I have created a very small test database called 'Goldenstar'
The database has various columns in it, one of which is called Prod_name. This column, as the name suggests, has the names (strings) of the products for a Chinese takeaway.

I have written the below script, and the only output I get from the browser is:

No its only Array

I'm not sure if the PHP or the Database is at fault.
The script is:

<?php

$cxn=mysqli_connect("localhost","root","password","Goldenstar")
or die ("No Mushroom!");

$dish="Chicken Chop Suey";

$query = "SELECT prod_name FROM products";

$result = mysqli_query($cxn,$query)
or die ("Couldn't Execute Query Erdes!");

$row = mysqli_fetch_assoc ($result);

if ( $row['Prod_Name'] == "Chop Suey" )

{

echo "Yes its ". $row;

}

else

{

echo "No its only ". $row ."<br/>";

}

?>

I expected to see a list of the various Chinese dishes with

No its only Beef Curry
etc until the script got to
Chicken Chop Suey
. Instead I just get
 No its only Array
. Please help if you can.

Thanks

Lee.

[edited by: eelixduppy at 10:45 pm (utc) on Mar. 19, 2008]
[edit reason] removed specifics [/edit]

Habtom

4:11 am on Mar 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



while ($row = mysqli_fetch_assoc ($result)) {
if ( $row['Prod_Name'] == "Chop Suey" )
{
echo "Yes its ". $row['Prod_Name'];
}
else
{
echo "No its only ". $row['Prod_Name'] ."<br/>";
}
}