Jump to content

Recommended Posts

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!!
Link to comment
https://forums.phpfreaks.com/topic/21843-php-mysql-quick-question-please-help/
Share on other sites

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]
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]
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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.