Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old January 26th, 2005, 03:01 PM
edlavalette edlavalette is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 8 edlavalette User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old January 26th, 2005, 04:43 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
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"]

Reply With Quote
  #3  
Old February 9th, 2005, 01:57 AM
edlavalette edlavalette is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 8 edlavalette User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: 2 table select output to html

Thank you. It worked perfectly.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > 2 table select output to html


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT