Jump to content

Archived

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

l!m!t

PHP MySQL quick question please help.

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!!

Share this post


Link to post
Share on other sites

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 2

Thanks for the help!!

Share this post


Link to post
Share on other sites

Also, I notice its also including 1 any way to just get it so it does only 0 and 2 ?

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

The first code works great, only its including "1" I only need 0 and 2.

Thanks again I really appreciate it!

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

Hi sorry about all the questions, but where does (..) go ? I am still new to this any addtional help would be great.

Thanks again.

Share this post


Link to post
Share on other sites
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 

Share this post


Link to post
Share on other sites

×

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.