Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aDxcf-0003Wl-KL for pgsql-php@arkaria.postgresql.org; Tue, 29 Dec 2015 16:59:45 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aDxcf-0000Uq-6t for pgsql-php@arkaria.postgresql.org; Tue, 29 Dec 2015 16:59:45 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aDxce-0000Sq-KT for pgsql-php@postgresql.org; Tue, 29 Dec 2015 16:59:44 +0000 Received: from teladesign.vm.bytemark.co.uk ([89.16.172.204]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1aDxcc-0001fc-1I for pgsql-php@postgresql.org; Tue, 29 Dec 2015 16:59:43 +0000 Received: from [109.76.177.57] (helo=[127.0.0.1]) by teladesign.vm.bytemark.co.uk with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1aDxcZ-0006iO-Lz; Tue, 29 Dec 2015 16:59:39 +0000 Reply-To: rod@iol.ie Subject: Re: How to limit dropdown list to options based on 'in use' rows from lookup table, for webpage using php and postgresql References: <5682B63E.9030008@iol.ie> To: Killian Driscoll , PostgreSQLPHP From: Raymond O'Donnell X-Enigmail-Draft-Status: N1110 Message-ID: <5682BBF3.1020605@iol.ie> Date: Tue, 29 Dec 2015 16:59:31 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-php Precedence: bulk Sender: pgsql-php-owner@postgresql.org On 29/12/2015 16:47, Killian Driscoll wrote: > Hi, > I posted my reply to the pgsql-php mailing list but in the meantime I > got an email to say I was removed from the list: I just joined it so I > don't know why I was removed.... Hi Killian, Odd - I'll post this to the list also so others will see it. > Anyhow, below is the reply I tried to post: > > Apologies - 'in use' is my grasping at describing it, and as I guessed > it was unclear. By 'in use' I mean that from my 50 lookup options for > county types, to date in the db only 20 country types have been used, > i.e. my db's countries are of 20 types, e.g. country 1 is type > 'glorious', country 2 is type 'barren', but no country so far is type > 'lucky': when one uses the webpage filter I only want the type lookups > used to date to be seen, i.e. 'glorious' or 'barren', but not 'lucky' as > the latter would result in a "There are no records to display" message. Ah, OK, I understand now. I'd imagine a simple inner join between the two tables should do the trick - you'll get only those rows which exist in both tables. Something like this: select [whatever] from country_table ct inner join lookup_table lt on (ct.country_type_id = lt.country_type_id) [etc] Is this what you need? Hope the weather's a bit better in Dublin than it is here in Galway - we're getting lashed by Frank at the moment. :-) Ray. -- Raymond O'Donnell :: Galway :: Ireland rod@iol.ie -- Sent via pgsql-php mailing list (pgsql-php@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-php