Solved

php mysql query

Posted on 2013-05-29
3
255 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 7

Author Comment

by:Robert Saylor
ID: 39205290
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
ID: 39205349
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 7

Author Comment

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

Thanks!
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

860 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