Jump to content

Pulling Data From Two Tables


kulmu

Recommended Posts

Basically the end result for this is to manage rental properties.

 

"properties" is the main table that handles most the information. It has about 50 rows so I am not sure you need all the rows, but if you do let me know.

 

The second table has floor plans. I named this table "floorplans". It has several rows:

 

PlanID

PropID - this is the same one from the properties table that they both share

PlanName

Size

Bedrooms

Bathrooms

Den

Price

PriceTo

Deposit

SqFt

UnitImg

 

I am attempting to build a cataloging system and display the results as a set on the page. I am listing 10 items per page with various sub info on that page as well. Most of this information is in the primary 'properties' table, but I would also like to be able to list items from the sub table that match the primary ID all on the same page. A detailed page containing all the information on the subject would be easier to do since I could just call the ID from the $_GET on two separate querrys but I am trying to make a page to give previews before clicking through.

 

Any help is greatly appreciated.

 

Link to comment
https://forums.phpfreaks.com/topic/51005-pulling-data-from-two-tables/
Share on other sites

How is going to be the preview?

It could be a popup that opens when you click an specific link in the list? If so, you can use another file for the popup window which  also receives a GET param, and show the information what you want.

 

I am a little bit confused with: "but I would also like to be able to list items from the sub table that match the primary ID all on the same page"

 

I guess you want to show information from both tables in the items on the list. In that case you will need to execute a query that joins those tables using the PropID as the "linker".

 

If is not that case. Just ignore the following code.

 

Example.

 

$sql = "select a.*,b.Bedrooms,b.Bathrooms from properties as a,floorplans as b where a.PropID=b.PropID"

 

This query will give you all the information from table properties and the Bedrooms,Bathrooms from the floorplans table. All this info in the same row per result.

 

Hope this helps. ::)

--> irvieto <--

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.