switch or if statements when doing sql

PHP coding talk.

Moderator: Moderators

switch or if statements when doing sql

Postby webnoobie on Tue Mar 13, 2007 3:42 pm

hello,

i am trying to find the best way possible to somewhat search, a database table for certain information. when the user first goes to a page, he there is two input fields. one is for an ad name and the second is for ad owner.

now, this is what i have for my php code:
Code: Select all
               if( $ad_name )
         {
            $sql_where .= "WHERE ad_name LIKE '%$ad_name%'";
         }
         else if( $ad_owner )
         {
            $ad_owner_convert = get_userdata($ad_owner_convert);
            $ad_owner_userid = $ad_owner_convert['ad_owner_userid'];
            
            $sql_where .= "WHERE ad_owner LIKE '%$ad_owner_userid%'";
         }
         
         $sql = "SELECT *
            FROM " . ADS_TABLE . "
            $sql_where";
         if( !($result = $db->sql_query($sql)) )
         {
            message_die(GENERAL_ERROR, 'Could not perform search correctly', '', __LINE__, __FILE__, $sql);
         }
         while( $row = $db->sql_fetchrow($result) )
         {
            echo $row['ad_id'] . ' ' . $row['ad_name'] . '<br />';
         }


But i would like to use the best way possible to do this. Could someone help me and also perhaps show me the way to do it using a switch case statements. Thank you in advance! It is most appreciated.
Best Regards:
webnoobie
webnoobie
Registered User
Registered User
 
Posts: 366
Joined: Wed Jun 08, 2005 10:38 pm
Location: My Computer

Re: switch or if statements when doing sql

Postby ioswebstorecom on Tue Apr 07, 2009 12:54 am

hm ..it work?
-------------------------------------------------------------
INNOVATIVE ON LINE SOLUITIONS
240-249-0393
ioswebstore.com
ioswebstorecom
Registered User
Registered User
 
Posts: 2
Joined: Tue Apr 07, 2009 12:40 am

Re: switch or if statements when doing sql

Postby floridamary4 on Mon Apr 20, 2009 12:45 pm

yeah it works. :)
thanks for the info :)
floridamary4
Registered User
Registered User
 
Posts: 12
Joined: Mon Apr 06, 2009 12:22 pm


Return to PHP Programming

Who is online

Users browsing this forum: No registered users and 4 guests

cron