Re: mysql case statement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



no

On Sun, Jun 27, 2010 at 8:29 PM, David McGlone <david@xxxxxxxxxxxxx> wrote:

> On Sunday 27 June 2010 04:08:24 Tanel Tammik wrote:
> > Hello,
> >
> > how to select only if value is present?
> >
> >     $query = $db->query("select menus.id, menus.name,
> >       case
> >         when panels.id is not null then '1'
> >         end as hiddenpanel
> >
> >     from " . \DB_MENUS . " as menus
> >       left join " . \DB_HIDDENPANELS . " as panels on (menus.id =
> > panels.menu_id)
> >     where menus.id='" . (int)$id . "'
> >     ");
> >
> > i would like to select hiddenpanel only if there is a corresponding value
> >  in DB_HIDDENPANELS. At the moment i get NULL if there is no
> corresponding
> >  value in HIDDENPANELS table!
>
> I would use an if statement since you only need to determine true or false.
> Something like:
>
> $query = $db->query("select menus.id, menus.name,
>      from " . \DB_MENUS . " as menus
>       left join " . \DB_HIDDENPANELS . " as panels on (menus.id =
>  panels.menu_id)
>     where menus.id='" . (int)$id . "'
>     ");
>
> if (empty(DB_HIDDENPANELS)) {
>        echo "";
>
> }
>
> else {
>        echo "hiddenpanel";
>
> }
>
> But I would wait for others to chime in on this one, because I'm very far
> from
> an expert, there's also got to be a much better efficient way to write the
> if
> statement above, but it's what I would do in a case like this until I found
> a
> better way.
>
> --
> Blessings,
> David M.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
A Brandon_R Production

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux