|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
2 table select output to html
I have two tables which have this structure:
Location Field Type id mediumint(10) Name varchar(30) Address varchar(40) City varchar(20) State tinyint(2) Zip mediumint(5) Phone varchar(12) URL varchar(30) Event Field Type Name varchar(30) Date date Time varchar(20) Location mediumint(10) State tinyint(2) Description text Cost decimal(5,0) Note: Event.Location = Location.id [with a many to one releationship] Then I use this select stament: $result = mysql_query("SELECT Event.Name, Event.Date, Event.Time, Event.Location, Event.Description, Event.Cost, Location.id, Location.State FROM Event, Location WHERE Event.State = $StateID and CURDATE() <= Date and DATE_ADD(CURDATE(),INTERVAL 30 DAY) >= Date") or die(mysql_error()); while ( $row = mysql_fetch_array($result) ) { echo("<P>" . $row["Name"] . " > " . $row["Date"] . " > " . $row["Time"] . " > " . $row["Location"] . " > " . $row["Description"] . " > " . $row["Cost"] . "</P>"); } What I can't figure out is how to display the values from the Location Table for Location.Name and Location.City. I tried some table joins but I'm not sure that is the correct [and easiest] way to solve the problem. Can anyone offer assistance? Thanks. |
|
#2
|
|||
|
|||
|
RE: 2 table select output to html
try using a join like so...
SELECT Event.Name, Event.Date, Event.Time, Event.Location, Event.Description, Event.Cost, Location.id, Location.State FROM Event join Location on Event.location = Location.id WHERE Event.State = $StateID and CURDATE() <= Date and DATE_ADD(CURDATE(),INTERVAL 30 DAY) >= Date since you have column names in both tables that are the same, you will need to use aliases for the field names. so in order to see Location.name, add it to the select query like so Location.Name as LocName then just reference the alias $row["LocName"] |
|
#3
|
|||
|
|||
|
RE: 2 table select output to html
Thank you. It worked perfectly.
|
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > 2 table select output to html |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|