I have been staring at this for far too long to admit, but I am stumped. I am a newbie to PHP and MySQL but have a relatively good grasp on SQL, so I would like to think I know what I am doing here. Unfortunately, results prove different.
I have built a simple form to submit information into a very simple MySQL dbase - will expand it later when the client firms up the requirements. The submission part works.
Now to pull the results. I can get a simple 'SELECT * FROM table' to work, but when I try to insert a WHERE parameter, I get a syntax error.
Here is the code on the page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Dynamic Menu</title>
</head>
<body>
<?
// Make a MySQL Connection
include("dbinfo.inc.php");
mysql_connect(localhost,$u
sername,$p
assword);
@mysql_select_db($database
) or die( "Unable to select database");
// Retrieve all the data from the "example" table
$result = mysql_query("SELECT * FROM test1 WHERE show = '1'")
or die(mysql_error());
// store the record of the "example" table into $row
$row = mysql_fetch_array( $result );
// Print out the contents of the entry
while($row = mysql_fetch_assoc($result)
)
{
echo "Title :{$row['title']} <br>" .
"Description : {$row['description']} <br>" .
"Price : {$row['price']} <br><br>";
}
?>
</body>
</html>
Like I said - this works fine until I add the 'WHERE show = '1'.
My thinking is the show field in the dbase table is a bit flag - true or false - that indicates if a particular entry should be visible or not. I have tried setting the field type to tinyint (1 or 0), varchar (1 or 0), or boolean. I have tried permutations of 'show is 1', 'show is true', 'show > 0' and 'show = '1' '.
I hate to say how much time I have spent on this one particular piece - it is killing me. As near as I can tell, the PHP/MYSQL dbase does not have bit value, so should I be using tinyint? VARCHAR? What is the syntax to successfully query against it?
Thanks in advance!
Our community of experts have been thoroughly vetted for their expertise and industry experience.