l!m!t Posted September 24, 2006 Share Posted September 24, 2006 Hello,I am new to PHP and MySQL, but am learning quickly. I have been stuck on this for over 3 hours :) I have an SQL query that I want to send a couple of numbers to. The numbers are 0 and 3 any idea how I can do this ? I will paste what I have below.[code] $find= "where c.customers_lastname like '%" . $keywords . "%' or c.customers_firstname like '%" . $keywords . "%' or c.customers_email_address like '%" . $keywords . "' and member_level = '0'";[/code]I want member_level to include [b]"0" and "2"[/b] in its search.Thanks for your time!! Quote Link to comment https://forums.phpfreaks.com/topic/21843-php-mysql-quick-question-please-help/ Share on other sites More sharing options...
Barand Posted September 24, 2006 Share Posted September 24, 2006 ... AND member_level IN (0 , 2) Quote Link to comment https://forums.phpfreaks.com/topic/21843-php-mysql-quick-question-please-help/#findComment-97538 Share on other sites More sharing options...
l!m!t Posted September 24, 2006 Author Share Posted September 24, 2006 Thanks A lot! Worked Perfect!!Just one more quick question how would I format it for this type of query?if ($find =='') $search = "where member_level = '0'"; // again I want 0 and 2Thanks for the help!! Quote Link to comment https://forums.phpfreaks.com/topic/21843-php-mysql-quick-question-please-help/#findComment-97544 Share on other sites More sharing options...
l!m!t Posted September 24, 2006 Author Share Posted September 24, 2006 Also, I notice its also including 1 any way to just get it so it does only 0 and 2 ? Quote Link to comment https://forums.phpfreaks.com/topic/21843-php-mysql-quick-question-please-help/#findComment-97547 Share on other sites More sharing options...
Barand Posted September 24, 2006 Share Posted September 24, 2006 I usually use the IN syntax when processing arrays of values eg[code]<?php$selects = array (0,2);$selectStr = join ("','" , $selects); //--> 0','2$sql = "SELECT blah FROM tablename WHERE x IN ('$selectStr')"; // --> ... IN ('0','2')?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21843-php-mysql-quick-question-please-help/#findComment-97550 Share on other sites More sharing options...
l!m!t Posted September 24, 2006 Author Share Posted September 24, 2006 The first code works great, only its including "1" I only need 0 and 2. Thanks again I really appreciate it! Quote Link to comment https://forums.phpfreaks.com/topic/21843-php-mysql-quick-question-please-help/#findComment-97553 Share on other sites More sharing options...
Barand Posted September 24, 2006 Share Posted September 24, 2006 Post your query code. It should pull only 0 and 2 Quote Link to comment https://forums.phpfreaks.com/topic/21843-php-mysql-quick-question-please-help/#findComment-97554 Share on other sites More sharing options...
l!m!t Posted September 24, 2006 Author Share Posted September 24, 2006 Hi[code] $search = ''; if ( ($HTTP_GET_VARS['search']) && (tep_not_null($HTTP_GET_VARS['search'])) ) { $keywords = tep_db_input(tep_db_prepare_input($HTTP_GET_VARS['search'])); $search = "where c.customers_lastname like '%" . $keywords . "%' or c.customers_firstname like '%" . $keywords . "%' or c.customers_email_address like '%" . $keywords . "' AND member_level IN (0 , 2)"; } if ($search =='') $search = " AND member_level IN (0 , 2)";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21843-php-mysql-quick-question-please-help/#findComment-97565 Share on other sites More sharing options...
Barand Posted September 24, 2006 Share Posted September 24, 2006 You need (..) when mixing AND and OR in queries[code]<?php$search = "where ((c.customers_lastname like '%$keywords%') or (c.customers_firstname like '%$keywords%') or (c.customers_email_address like '%$keywords%')) AND member_level IN (0 , 2)";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21843-php-mysql-quick-question-please-help/#findComment-97568 Share on other sites More sharing options...
l!m!t Posted September 24, 2006 Author Share Posted September 24, 2006 Hi sorry about all the questions, but where does (..) go ? I am still new to this any addtional help would be great. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/21843-php-mysql-quick-question-please-help/#findComment-97579 Share on other sites More sharing options...
Barand Posted September 24, 2006 Share Posted September 24, 2006 LOL.I'll reword it for you."You need parentheses when mixing AND and OR in queries"I put them in for you in the code I posted Quote Link to comment https://forums.phpfreaks.com/topic/21843-php-mysql-quick-question-please-help/#findComment-97600 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.