问题描述:

Could not get data: Unknown column erro in php and mysql database when calling data from database

I need to show the item with subitem as sub category

I need that item and sub-item both come from database.

like

 item1

-subitem1

-subitem2

item2

-subitem1

item

$sql = 'SELECT * FROM main';

mysql_select_db('vishic3w_packages');

$retval = mysql_query( $sql, $conn );

if(! $retval )

{

die('Could not get data: ' . mysql_error());

}

while($row = mysql_fetch_array($retval, MYSQL_ASSOC))

{

echo "<ul/><li/> {$row['items']} <br/></li></ul> ";

$items=$row['items'];

{

$sql1 = "SELECT * FROM subitem where subitem.item = $items ";

$retval1 = mysql_query( $sql1);

if(! $retval1 )

{

die('Could not get data: ' . mysql_error());

}

while($row = mysql_fetch_array($retval, MYSQL_ASSOC))

{

echo "<ul/><li/> {$row['subitem']} <br/></li></ul> ";

}

}}

I want to show the items with their sub items from other table, but after script execute the following error shows

Drinks

Could not get data: Unknown column 'Drinks' in 'where clause'

the output can be seen herehttp://www.indowesterncaterers.com/catering-packages.php

the databse has these entries shown in the image attached shows the data from table "subitem"

http://s16.postimg.org/6si26jwjp/data.png

网友答案:

I think you are getting single quote around variable "$items" in your query. If it is so, first print the query like below:

echo $sql1 = "SELECT * FROM subitem where subitem.item = $items ";

and try to remove the single quotes.

网友答案:

Try this

$sql1 = "SELECT * FROM subitem where item like \'$items\'";
相关阅读:
Top