Jump to content


Photo

PHP MySQL quick question please help.


  • Please log in to reply
10 replies to this topic

#1 l!m!t

l!m!t
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 24 September 2006 - 06:39 AM

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.

 $find= "where c.customers_lastname like '%" . $keywords . "%' or c.customers_firstname like '%" . $keywords . "%' or c.customers_email_address like '%" . $keywords . "' and member_level = '0'";


I want member_level to include "0" and "2" in its search.

Thanks for your time!!

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 24 September 2006 - 07:35 AM

... AND member_level IN (0 , 2)
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 l!m!t

l!m!t
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 24 September 2006 - 07:57 AM


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

#4 l!m!t

l!m!t
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 24 September 2006 - 08:02 AM


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

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 24 September 2006 - 08:10 AM

I usually use the IN syntax when processing arrays of values eg
<?php
$selects = array (0,2);
$selectStr = join ("','" , $selects);    //--> 0','2
$sql = "SELECT blah FROM tablename WHERE x IN ('$selectStr')"; // --> ... IN ('0','2')
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 l!m!t

l!m!t
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 24 September 2006 - 08:14 AM


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

Thanks again I really appreciate it!

#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 24 September 2006 - 08:19 AM

Post your query code. It should pull only 0 and 2
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#8 l!m!t

l!m!t
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 24 September 2006 - 08:50 AM

Hi




    $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)";






#9 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 24 September 2006 - 08:57 AM

You need (..) when mixing AND and OR in queries

<?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)";
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#10 l!m!t

l!m!t
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 24 September 2006 - 09:22 AM


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

Thanks again.

#11 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 24 September 2006 - 10:50 AM

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 
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users