Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

WwWXxX, udp high ports, d-link extract firmware dsl-2750u, wwwwxxxxx.2G, yxxxcom, WWWXXX, ftp://192.168.100.100, wwwxxx 100, www.xxxcon, wwwxxx

Links

XODOX
Impressum

#1: SELECT syntax

Posted on 2011-10-12 21:24:44 by ron.piggott

------=_NextPart_000_0033_01CC88F3.11B09F40
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable


In my Bible_Trivia table I have the columns

`trivia_answer_1`, `trivia_answer_2`, `trivia_answer_3`, =
`trivia_answer_4`, `answer`

`answer` is an integer always with a value of 1 to 4. Is there a way to =
use the value of `answer` to only select the correct trivia answer?

This doesnâÂ=99t work, but this is the idea I am trying to achieve:

SELECT `trivia_answer_`answer`` FROM `Bible_trivia`

Thanks in advance,

Ron



www.TheVerseOfTheDay.info=20

------=_NextPart_000_0033_01CC88F3.11B09F40--

Report this message

#2: RE: SELECT syntax

Posted on 2011-10-12 22:08:05 by Toby Hart Dyke

Not terribly elegant, but this should work:

SELECT `trivia_answer_1` AS `trivia_answer` FROM `Bible_trivia` WHERE =
`answer`=3D1
UNION
SELECT `trivia_answer_2` AS `trivia_answer` FROM `Bible_trivia` WHERE =
`answer`=3D2
UNION
SELECT `trivia_answer_3` AS `trivia_answer` FROM `Bible_trivia` WHERE =
`answer`=3D3
UNION
SELECT `trivia_answer_4` AS `trivia_answer` FROM `Bible_trivia` WHERE =
`answer`=3D4;

I have to say that it's likely that your design may not be the most =
optimal. What happens if you want 5 answers? Or 6?

Toby


-----Original Message-----
From: Ron Piggott [mailto:ron.piggott@actsministries.org]=20
Sent: Wednesday, October 12, 2011 3:25 PM
To: php-db@lists.php.net
Subject: [PHP-DB] SELECT syntax


In my Bible_Trivia table I have the columns

`trivia_answer_1`, `trivia_answer_2`, `trivia_answer_3`, =
`trivia_answer_4`, `answer`

`answer` is an integer always with a value of 1 to 4. Is there a way to =
use the value of `answer` to only select the correct trivia answer?

This doesnâÂ=99t work, but this is the idea I am trying to achieve:

SELECT `trivia_answer_`answer`` FROM `Bible_trivia`

Thanks in advance,

Ron



www.TheVerseOfTheDay.info=20


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#3: Re: SELECT syntax

Posted on 2011-10-12 23:56:19 by Jack van Zanen

--90e6ba1eee6e17ca7404af21180e
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

Hi

In Oracle (and maybe others) you can use


select case
when answer=3D1
then trivia_answer_1
when answer=3D2
then trivia_answer_2
when answer=3D3
then trivia_answer_3
when answer=3D4
then trivia_answer_4
else null
end answer
from bible_trivia_table
OR

You can select all of them and process in PHP, should not be too hard to
come up with a couple of lines of code to display only 1 variable based on
the value of variable 5. Overhead should be pretty minimal as well
You'll be writing something to display a value anyway


Jack van Zanen

-------------------------
This e-mail and any attachments may contain confidential material for the
sole use of the intended recipient. If you are not the intended recipient,
please be aware that any disclosure, copying, distribution or use of this
e-mail or any attachment is prohibited. If you have received this e-mail in
error, please contact the sender and delete all copies.
Thank you for your cooperation


On Thu, Oct 13, 2011 at 6:24 AM, Ron Piggott <ron.piggott@actsministries.or=
g
> wrote:

>
> In my Bible_Trivia table I have the columns
>
> `trivia_answer_1`, `trivia_answer_2`, `trivia_answer_3`, `trivia_answer_4=
`,
> `answer`
>
> `answer` is an integer always with a value of 1 to 4. Is there a way to u=
se
> the value of `answer` to only select the correct trivia answer?
>
> This doesn=92t work, but this is the idea I am trying to achieve:
>
> SELECT `trivia_answer_`answer`` FROM `Bible_trivia`
>
> Thanks in advance,
>
> Ron
>
>
>
> www.TheVerseOfTheDay.info <http://www.theverseoftheday.info/>
>

--90e6ba1eee6e17ca7404af21180e--

Report this message

#4: Re: SELECT syntax

Posted on 2011-10-13 06:04:02 by Amit Tandon

--20cf303bfb564d488104af263c7e
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

select case<http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.h=
tml>
works in mysql also
============
regds
amit

"The difference between fiction and reality? Fiction has to make sense."


On Thu, Oct 13, 2011 at 3:26 AM, Jack van Zanen <jack@vanzanen.com> wrote:

> Hi
>
> In Oracle (and maybe others) you can use
>
>
> select case
> when answer=3D1
> then trivia_answer_1
> when answer=3D2
> then trivia_answer_2
> when answer=3D3
> then trivia_answer_3
> when answer=3D4
> then trivia_answer_4
> else null
> end answer
> from bible_trivia_table
> OR
>
> You can select all of them and process in PHP, should not be too hard to
> come up with a couple of lines of code to display only 1 variable based =
on
> the value of variable 5. Overhead should be pretty minimal as well
> You'll be writing something to display a value anyway
>
>
> Jack van Zanen
>
> -------------------------
> This e-mail and any attachments may contain confidential material for the
> sole use of the intended recipient. If you are not the intended recipient=
,
> please be aware that any disclosure, copying, distribution or use of this
> e-mail or any attachment is prohibited. If you have received this e-mail =
in
> error, please contact the sender and delete all copies.
> Thank you for your cooperation
>
>
> On Thu, Oct 13, 2011 at 6:24 AM, Ron Piggott <
> ron.piggott@actsministries.org
> > wrote:
>
> >
> > In my Bible_Trivia table I have the columns
> >
> > `trivia_answer_1`, `trivia_answer_2`, `trivia_answer_3`,
> `trivia_answer_4`,
> > `answer`
> >
> > `answer` is an integer always with a value of 1 to 4. Is there a way to
> use
> > the value of `answer` to only select the correct trivia answer?
> >
> > This doesnâÂ=99t work, but this is the idea I am trying to achieve:
> >
> > SELECT `trivia_answer_`answer`` FROM `Bible_trivia`
> >
> > Thanks in advance,
> >
> > Ron
> >
> >
> >
> > www.TheVerseOfTheDay.info <http://www.theverseoftheday.info/>
> >
>

--20cf303bfb564d488104af263c7e--

Report this message

#5: Re: SELECT syntax

Posted on 2011-10-13 06:05:55 by Amit Tandon

--90e6ba613c7c10547904af2643c8
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

another example<http://mysql-tips.blogspot.com/2005/04/mysql-select-case-ex=
ample.html>
============
regds
amit

"The difference between fiction and reality? Fiction has to make sense."


On Thu, Oct 13, 2011 at 9:34 AM, Amit Tandon <attand@gmail.com> wrote:

> select case<http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions=
..html> works in mysql also
> ============
> regds
> amit
>
> "The difference between fiction and reality? Fiction has to make sense."
>
>
>
> On Thu, Oct 13, 2011 at 3:26 AM, Jack van Zanen <jack@vanzanen.com> wrote=
:
>
>> Hi
>>
>> In Oracle (and maybe others) you can use
>>
>>
>> select case
>> when answer=3D1
>> then trivia_answer_1
>> when answer=3D2
>> then trivia_answer_2
>> when answer=3D3
>> then trivia_answer_3
>> when answer=3D4
>> then trivia_answer_4
>> else null
>> end answer
>> from bible_trivia_table
>> OR
>>
>> You can select all of them and process in PHP, should not be too hard to
>> come up with a couple of lines of code to display only 1 variable based
>> on
>> the value of variable 5. Overhead should be pretty minimal as well
>> You'll be writing something to display a value anyway
>>
>>
>> Jack van Zanen
>>
>> -------------------------
>> This e-mail and any attachments may contain confidential material for th=
e
>> sole use of the intended recipient. If you are not the intended recipien=
t,
>> please be aware that any disclosure, copying, distribution or use of thi=
s
>> e-mail or any attachment is prohibited. If you have received this e-mail
>> in
>> error, please contact the sender and delete all copies.
>> Thank you for your cooperation
>>
>>
>> On Thu, Oct 13, 2011 at 6:24 AM, Ron Piggott <
>> ron.piggott@actsministries.org
>> > wrote:
>>
>> >
>> > In my Bible_Trivia table I have the columns
>> >
>> > `trivia_answer_1`, `trivia_answer_2`, `trivia_answer_3`,
>> `trivia_answer_4`,
>> > `answer`
>> >
>> > `answer` is an integer always with a value of 1 to 4. Is there a way t=
o
>> use
>> > the value of `answer` to only select the correct trivia answer?
>> >
>> > This doesnâÂ=99t work, but this is the idea I am trying to achieve=
:
>> >
>> > SELECT `trivia_answer_`answer`` FROM `Bible_trivia`
>> >
>> > Thanks in advance,
>> >
>> > Ron
>> >
>> >
>> >
>> > www.TheVerseOfTheDay.info <http://www.theverseoftheday.info/>
>> >
>>
>
>

--90e6ba613c7c10547904af2643c8--

Report this message

#6: Re: SELECT syntax

Posted on 2011-10-13 09:32:47 by Karl DeSaulniers

Or something like this?
SELECT * FROM `Bible_trivia` WHERE answer=`answer`;
Then match the results to trivia_answer_1 in php to see if correct.

if($trivia_answer_1 == $results) {
.... do this
}

or a switch

switch ($results) {
case $trivia_answer_1:
... do this
case $trivia_answer_2
... do this

Best,
Karl

On Oct 12, 2011, at 11:04 PM, Amit Tandon wrote:

>>> SELECT `trivia_answer_`answer`` FROM `Bible_trivia`

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#7: Re: SELECT syntax

Posted on 2011-10-13 10:06:08 by Karl DeSaulniers

--Apple-Mail-1-883552398
Content-Type: text/plain;
charset=US-ASCII;
format=flowed;
delsp=yes
Content-Transfer-Encoding: 7bit

Heh,
Thanks Karthik. Not my post.. :)
But your solution looks dead on..

Here you go Ron. Try this one.

Best,
Karl


On Oct 13, 2011, at 2:42 AM, Karthik S wrote:

> Try this,
>
> select
> CASE answer
> when 1 then trivia_answer_1
> when 2 then trivia_answer_2
> when 3 then trivia_answer_3
> when 4 then trivia_answer_4
> END as trivia_answers
> from bible_trivia_table
>
> On Thu, Oct 13, 2011 at 1:02 PM, Karl DeSaulniers <karl@designdrumm.com
> > wrote:
> Or something like this?
> SELECT * FROM `Bible_trivia` WHERE answer=`answer`;
> Then match the results to trivia_answer_1 in php to see if correct.
>
> if($trivia_answer_1 == $results) {
> ... do this
> }
>
> or a switch
>
> switch ($results) {
> case $trivia_answer_1:
> ... do this
> case $trivia_answer_2
> ... do this
>
> Best,
> Karl
>
>
> On Oct 12, 2011, at 11:04 PM, Amit Tandon wrote:
>
> SELECT `trivia_answer_`answer`` FROM `Bible_trivia`
>
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--Apple-Mail-1-883552398--

Report this message