We help IT Professionals succeed at work.
Get Started

using PHP and MySQL to build a web query

chipsterva69 asked
Last Modified: 2013-12-12
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">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Dynamic Menu</title>


// Make a MySQL Connection
@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>";



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!
Watch Question
This problem has been solved!
Unlock 3 Answers and 8 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE