TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-16-2009, 04:21 PM   #1 (permalink)
The Contributor
 
Sakakuchi's Avatar
 
Join Date: Feb 2009
Posts: 64
Thanks: 1
Sakakuchi is on a distinguished road
Default 2nd table

Hi there,

Is it possible to make an query like:

Table 1: id;nickname(unique);rights
Table 2: id;email;nickname

Now I want to select the email where rights equals to 3.

Is it possible to write that in one single query?

(The tables cannot be put together in one because thats an excisting system...)

Last edited by Sakakuchi : 03-16-2009 at 04:23 PM. Reason: Explained better
Sakakuchi is offline  
Reply With Quote
Old 03-16-2009, 05:36 PM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

You want to look up what's called a 'join', ie; http://www.w3schools.com/Sql/sql_join.asp

PHP Code:
SELECT t1.idt1.nicknamet2.email FROM table1 AS t1 INNER JOIN table2 AS t2 ON t1.id=t2.id WHERE t1.rights 
Broken down:

PHP Code:
SELECT t1.idt1.nicknamet2.email
// Select the id, nickname and email data. We don't need to select the rights, we already know
// everybody selected from this query should be equal to 3

FROM table1 AS t1
// The primary table we're operating on

INNER JOIN table2 AS t2
// We use an inner join because we only want to return records where there is at least one
// row in both tables that match the join condition.

ON t1.id=t2.id
// The join condition

WHERE t1.rights 3
// Where the rights column of table one is equal to 3 
I haven't programmed in nearly 6 months so I could be a little rusty but I'm fairly certain this is what you're in the market for.
delayedinsanity is offline  
Reply With Quote
Old 03-17-2009, 06:29 AM   #3 (permalink)
The Contributor
 
Sakakuchi's Avatar
 
Join Date: Feb 2009
Posts: 64
Thanks: 1
Sakakuchi is on a distinguished road
Default

Yeah, that should do it. THX alot
Sakakuchi is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Databse structure Village Idiot TalkPHP Developer Team 3 01-16-2009 10:31 PM
This project has begun! Village Idiot TalkPHP Developer Team 40 01-01-2009 04:29 AM
Lookups table drewbee Advanced PHP Programming 0 07-15-2008 08:21 PM
Need your feedback Tanax Absolute Beginners 29 10-11-2007 04:50 PM
How to check if a table exists? Haris General 8 09-19-2007 09:04 PM


All times are GMT. The time now is 12:42 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design