Solved

php mysql query

Posted on 2013-05-29
3
252 Views
Last Modified: 2013-05-29
Hi, I am not sure if mysql can do this or not but figured I would ask:

1. I have a table with a column with this data point:
bunk = BA3-01B

2. I have a table as boats
column abbreviation = BA3

3. I have a table as bunks
boatID = 1
cabin = 01
bunk = B

Now in my inventory table I have a column called bunks with "BA3-01B"

I want to take "BA3-01B" and search "BA3" on table boats to get the boatID then search boatID, cabin "01" and bunk "B" from table bunks and return table bunks - cabin_type data.

Here is the query I was messing with. It did not error but did not return any results. I think I am on the right track.

SELECT
	`charters`.`boatID`,
	`boats`.`abbreviation`,
	`bunks`.`cabin_type`


FROM
	`inventory`,`charters`,`boats`,`bunks`

WHERE
	`inventory`.`inventoryID` = '9150099'
	AND `inventory`.`charterID` = `charters`.`charterID`
	AND `charters`.`boatID` = `boats`.`boatID`
	AND `boats`.`boatID` = `bunks`.`boatID`
	AND `inventory`.`bunk` = CONCAT(`boats`.`abbreviation` + '-' + `bunks`.`cabin`,`bunks`.`bunk`)

Open in new window

0
Comment
Question by:Robert Saylor
  • 2
3 Comments
 
LVL 6

Author Comment

by:Robert Saylor
Comment Utility
ok, I solved my own question :)

I created a temp table and inserted the char "-" then included that in my concat and the query returned the data I wanted.
0
 
LVL 40

Accepted Solution

by:
Sharath earned 500 total points
Comment Utility
Did you try this?
SELECT
	`charters`.`boatID`,
	`boats`.`abbreviation`,
	`bunks`.`cabin_type`
FROM
	`inventory`,`charters`,`boats`,`bunks`
WHERE
	`inventory`.`inventoryID` = '9150099'
	AND `inventory`.`charterID` = `charters`.`charterID`
	AND `charters`.`boatID` = `boats`.`boatID`
	AND `boats`.`boatID` = `bunks`.`boatID`
	AND `inventory`.`bunk` = CONCAT(`boats`.`abbreviation`,'-',`bunks`.`cabin`,`bunks`.`bunk`)

Open in new window

0
 
LVL 6

Author Comment

by:Robert Saylor
Comment Utility
No but I will. I was using the plus like in JavaScript. I bet that would do it as well.

Thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now