Jump to content

PHP MySQL quick question please help.


l!m!t

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.