473,408 Members | 2,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Need Help: Mysql Database Query;

Hi i am new to this, first time joined a forum. Anyway my problem is i have two tables:

table1: establishment(estNo mediumint, estName varchar, other details..) Primary key=estNo;

table2: foodType(food varchar(), estNo mediumint) Foreign key=estNo, Primary Key=(food, estNo);

user inputs: inputEstName for establishment and inputFood for foodType;

im trying to set up a query via php that does the following:
SELECT all establishment details from establisment
ONLY IF
establishment.estName=inputEstName;
foodType.estNo=establishment.estNo && foodType.food = inputFood;
(where I get the estNo when a record has been found for the estName input)

the query in php that i have got so far looks like this:
$select= "select estNo, estName, details from establishment
where estName=" . $inputEstName .
"AND establishment.estNo=foodType.estNo
AND foodType.food=" . $ inputFood;

Help would be much appreciated,

Eric
When you are in a forum the very first time: READ THE POSTING GUIDELINES!!, especially the part on enclsosing code with php, html ot code tags!! - Ronald
Nov 10 '06 #1
5 1805
cassbiz
202 100+
Expand|Select|Wrap|Line Numbers
  1. $select= "select estNo, estName, details from establishment
  2. where estName=" . $inputEstName .
  3. "AND establishment.estNo=foodType.estNo
  4. AND foodType.food=" . $ inputFood;
You can try to enter your select string like this. I have found it to work for me.

Expand|Select|Wrap|Line Numbers
  1. $select= ("SELECT estNo, estName, details FROM establishment
  2. WHERE estName='$inputEstName' AND establishment.estNo=foodType.estNo
  3. AND foodType.food='$inputFood'");
  4.  
Nov 10 '06 #2
in the where query part:
Expand|Select|Wrap|Line Numbers
  1. WHERE estName=$inputEstName AND establishment.estNo=foodType.estNo
  2. AND foodType.food=$inputFood";
  3.  
I get an error reporting "unknown column foodType.estNo in where clause".

I presume i need to define somewhere a connection to the foodType table to access the foodType.estNo field...

Eric
Nov 10 '06 #3
cassbiz
202 100+
in the where query part:
Expand|Select|Wrap|Line Numbers
  1. WHERE estName=$inputEstName AND establishment.estNo=foodType.estNo
  2. AND foodType.food=$inputFood";
  3.  
I get an error reporting "unknown column foodType.estNo in where clause".

I presume i need to define somewhere a connection to the foodType table to access the foodType.estNo field...

Eric
Try this code

Expand|Select|Wrap|Line Numbers
  1. $select= ("SELECT establishment.estNo, foodType.estNo, establishment.details FROM establishment,
  2. foodType WHERE establishment.estName='$inputEstName' AND establishment.estNo=foodType.estNo
  3. AND foodType.food='$inputFood'");
  4.  
Nov 10 '06 #4
cassbiz
202 100+
I got the following code from

builder.com
Nov 10 '06 #5
cheers that worked perfectly
Nov 10 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Erich Trowbridge | last post by:
Has anybody seen this tool? It is awesome. check out http://vw.vermeer.org/ . It's a php front end for large-scale syslog deployments. It makes managing syslog in large networks a snap. The idea...
3
by: James | last post by:
Please help - getting very desperate! Sun, 12 October 2003 05:39 I have PHPDEV 4.2.3 from Firepages.com.au as the upgrade to 4.3.0 did not work. I also had an abortive download from PHP.NET as...
6
by: Dal | last post by:
Help! I'm trying to get a login script to work. I get this error message MySQL Login Error: You have an error in your SQL syntax near ''jvsd0001_customers` WHERE cust_name='testuser' AND...
2
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers...
5
by: lkrubner | last post by:
I have a webserver through Rackspace. I create a domain. I create an FTP user. I upload some files. I create a database called testOfSetupScript and then I create a database user named setup. I...
1
by: Cern | last post by:
Is it somebody out there who has made a migration from an Oracle server to an MySQL server?? The scenario is as simply: I've got a Oracle 8 server with a database with content that I want to...
2
by: Jeffrey D Moncrieff | last post by:
I am trying to create a data base for colleting date for my research project. I have run in to a couple of problems and I need it fast ASAP I need it to be able to add data and edit them and view...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
2
by: dmstn | last post by:
Hey! I've got a little problem. I have to make a web site for a university essay. I curently have to create a search engine. Users can enter a hotel name in a search bar and results have to appear in...
3
by: fantomel | last post by:
<?php /* Create the mysql class_exists */ class mysql {
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.