[PHP-DB] Re: Multi search function (help)

2004-06-22 Thread Amit Arora
In that case you can do something like this:
$s_where = '';
foreach (array('name', 'lastname', 'nickname') as $e)
{
   $s_where .= (!empty($s_where) ? ' AND ' : '' ) . (!empty($_REQUEST[$e]) ? 
$e='$_REQUEST[$e]' : '' );
}
$result = mysql_query(SELECT id, name , lastname , m_date from users  . (!empty($s_where) ? 
 WHERE  . $s_where : '' ))
 or die(mysql_error());
HTH!
Regards,
Amit
www.digitalamit.com
Nabil wrote:
thanks .. but my question is not for isset... i m thinking consider that i
have 10 search fields... if i have to do a combination then i need a day to
right the various SQL statements

David Robley [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Nabil wrote:

hi all
Is there a way to condition your search:
-I have a form for four text boxes for search my Mysql...
-I don't want to write 4 conditions and for SQL statements incase he
decided not to search with all keywords (fields)
- I have by example : name, lastname , nickname and phone  form...
I need a way to select my records even one or more field were null
(searching only on of the above)
because the following SQL will generate null result
$name=$_POST['naame'];
$lastname=$_POST['lastname'];
$nickname=$_POST['nickname'];
$m_date=$_POST['m_dateY'];
echo $name.$lastname.$nickname.$m_date;
$sql = mysql_query(SELECT id, name , lastname , m_date from users where
name like binary '%$name%' and lastname like binary '%$lastname%'  and
nickname like binary  '%$nickname%' and m_date= YEAR('$m_date')  order
by
id ASC ) or die(mysql_error());

Thanks in advanced
Use isset to test whether the POST values are set and only include in the
query if there is a value.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP-DB] Re: Multi search function (help)

2004-05-28 Thread Gavin Amm
For what it's worth, if you store your form fields in an array, you can
loop through the array to search for isset  empty on each array element
and have the array add the fields that are relevant to your sql
statement.

Doing this will also ensure that you won't have to modify your script
(that generates the sql statement) regarding how many form fields you
have every time you add a new form field to the form page.

Gav

-Original Message-
From: nabil [mailto:[EMAIL PROTECTED] 
Sent: Thursday, 27 May 2004 10:57 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] Re: Multi search function (help)


yes, this is true, we should add empty() function too.

Ross Honniball [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 I'm not 100% sure, but you may want to also check if the field is
empty
 (using empty() function) before including in your search. (in addition
to
 isset)

 Also, just a caution, you will need to take some care in figuring when
and
 where to place your 'and' statements linking the various parts of the
query.

 At 08:01 AM 27/05/2004, you wrote:
 Nabil wrote:
 
   David Robley [EMAIL PROTECTED] wrote in message
   news:[EMAIL PROTECTED]
   Nabil wrote:
  
 hi all
   
Is there a way to condition your search:
   
-I have a form for four text boxes for search my Mysql...
-I don't want to write 4 conditions and for SQL statements
incase
he
decided not to search with all keywords (fields)
- I have by example : name, lastname , nickname and phone
form...
I need a way to select my records even one or more field were
null
(searching only on of the above)
   
because the following SQL will generate null result
   
   
$name=$_POST['naame'];
$lastname=$_POST['lastname'];
$nickname=$_POST['nickname'];
$m_date=$_POST['m_dateY'];
echo $name.$lastname.$nickname.$m_date;
   
SELECT id, name , lastname , m_date from users
where
name like binary '%$name%' and lastname like binary
'%$lastname%'
and
nickname like binary  '%$nickname%' and m_date= YEAR('$m_date')
order
   by
id ASC ) or die(mysql_error());
   
   
   
Thanks in advanced
  
   Use isset to test whether the POST values are set and only
include in
the
   query if there is a value.
 
   thanks .. but my question is not for isset... i m thinking
consider
that i
   have 10 search fields... if i have to do a combination then i need
a
day
   to right the various SQL statements
 
 So do something like:
 
 $query = SELECT id, name , lastname , m_date from users where 1 ;
 if (isset($_POST['name'])) {
$query .= AND name like binary '%{$-POST['name']}%' ;
 }
 if (isset($_POST['lastname'])) {
$query .= AND name like binary '%{$_post['lastname']}%' ;
 }
 //etc etc
 $query .=  order by id ASC ;
 $sql = mysql_query($query) or die(mysql_error());
 
 
 --
 David Robley
 
 Only cosmetologists give make-up exams.
 
 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

 .
 . Ross Honniball. JCU Bookshop Cairns, Qld, Australia.
 .

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Re: Multi search function (help)

2004-05-27 Thread nabil
yes, this is true, we should add empty() function too.

Ross Honniball [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 I'm not 100% sure, but you may want to also check if the field is empty
 (using empty() function) before including in your search. (in addition to
 isset)

 Also, just a caution, you will need to take some care in figuring when and
 where to place your 'and' statements linking the various parts of the
query.

 At 08:01 AM 27/05/2004, you wrote:
 Nabil wrote:
 
   David Robley [EMAIL PROTECTED] wrote in message
   news:[EMAIL PROTECTED]
   Nabil wrote:
  
 hi all
   
Is there a way to condition your search:
   
-I have a form for four text boxes for search my Mysql...
-I don't want to write 4 conditions and for SQL statements incase
he
decided not to search with all keywords (fields)
- I have by example : name, lastname , nickname and phone  form...
I need a way to select my records even one or more field were null
(searching only on of the above)
   
because the following SQL will generate null result
   
   
$name=$_POST['naame'];
$lastname=$_POST['lastname'];
$nickname=$_POST['nickname'];
$m_date=$_POST['m_dateY'];
echo $name.$lastname.$nickname.$m_date;
   
SELECT id, name , lastname , m_date from users
where
name like binary '%$name%' and lastname like binary '%$lastname%'
and
nickname like binary  '%$nickname%' and m_date= YEAR('$m_date')
order
   by
id ASC ) or die(mysql_error());
   
   
   
Thanks in advanced
  
   Use isset to test whether the POST values are set and only include in
the
   query if there is a value.
 
   thanks .. but my question is not for isset... i m thinking consider
that i
   have 10 search fields... if i have to do a combination then i need a
day
   to right the various SQL statements
 
 So do something like:
 
 $query = SELECT id, name , lastname , m_date from users where 1 ;
 if (isset($_POST['name'])) {
$query .= AND name like binary '%{$-POST['name']}%' ;
 }
 if (isset($_POST['lastname'])) {
$query .= AND name like binary '%{$_post['lastname']}%' ;
 }
 //etc etc
 $query .=  order by id ASC ;
 $sql = mysql_query($query) or die(mysql_error());
 
 
 --
 David Robley
 
 Only cosmetologists give make-up exams.
 
 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

 .
 . Ross Honniball. JCU Bookshop Cairns, Qld, Australia.
 .

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Re: Multi search function (help)

2004-05-26 Thread David Robley
Nabil wrote:

  hi all
 
 Is there a way to condition your search:
 
 -I have a form for four text boxes for search my Mysql...
 -I don't want to write 4 conditions and for SQL statements incase he
 decided not to search with all keywords (fields)
 - I have by example : name, lastname , nickname and phone  form...
 I need a way to select my records even one or more field were null
 (searching only on of the above)
 
 because the following SQL will generate null result
 
 
 $name=$_POST['naame'];
 $lastname=$_POST['lastname'];
 $nickname=$_POST['nickname'];
 $m_date=$_POST['m_dateY'];
 echo $name.$lastname.$nickname.$m_date;
 
 $sql = mysql_query(SELECT id, name , lastname , m_date from users where
 name like binary '%$name%' and lastname like binary '%$lastname%'  and
 nickname like binary  '%$nickname%' and m_date= YEAR('$m_date')  order by
 id ASC ) or die(mysql_error());
 
 
 
 Thanks in advanced

Use isset to test whether the POST values are set and only include in the
query if there is a value.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Re: Multi search function (help)

2004-05-26 Thread nabil
thanks .. but my question is not for isset... i m thinking consider that i
have 10 search fields... if i have to do a combination then i need a day to
right the various SQL statements



David Robley [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Nabil wrote:

   hi all
 
  Is there a way to condition your search:
 
  -I have a form for four text boxes for search my Mysql...
  -I don't want to write 4 conditions and for SQL statements incase he
  decided not to search with all keywords (fields)
  - I have by example : name, lastname , nickname and phone  form...
  I need a way to select my records even one or more field were null
  (searching only on of the above)
 
  because the following SQL will generate null result
 
 
  $name=$_POST['naame'];
  $lastname=$_POST['lastname'];
  $nickname=$_POST['nickname'];
  $m_date=$_POST['m_dateY'];
  echo $name.$lastname.$nickname.$m_date;
 
  $sql = mysql_query(SELECT id, name , lastname , m_date from users where
  name like binary '%$name%' and lastname like binary '%$lastname%'  and
  nickname like binary  '%$nickname%' and m_date= YEAR('$m_date')  order
by
  id ASC ) or die(mysql_error());
 
 
 
  Thanks in advanced

 Use isset to test whether the POST values are set and only include in the
 query if there is a value.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Re: Multi search function (help)

2004-05-26 Thread David Robley
Nabil wrote:

 David Robley [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 Nabil wrote:

   hi all
 
  Is there a way to condition your search:
 
  -I have a form for four text boxes for search my Mysql...
  -I don't want to write 4 conditions and for SQL statements incase he
  decided not to search with all keywords (fields)
  - I have by example : name, lastname , nickname and phone  form...
  I need a way to select my records even one or more field were null
  (searching only on of the above)
 
  because the following SQL will generate null result
 
 
  $name=$_POST['naame'];
  $lastname=$_POST['lastname'];
  $nickname=$_POST['nickname'];
  $m_date=$_POST['m_dateY'];
  echo $name.$lastname.$nickname.$m_date;
 
  SELECT id, name , lastname , m_date from users
  where
  name like binary '%$name%' and lastname like binary '%$lastname%'  and
  nickname like binary  '%$nickname%' and m_date= YEAR('$m_date')  order
 by
  id ASC ) or die(mysql_error());
 
 
 
  Thanks in advanced

 Use isset to test whether the POST values are set and only include in the
 query if there is a value.

 thanks .. but my question is not for isset... i m thinking consider that i
 have 10 search fields... if i have to do a combination then i need a day
 to right the various SQL statements

So do something like:

$query = SELECT id, name , lastname , m_date from users where 1 ;
if (isset($_POST['name'])) {
  $query .= AND name like binary '%{$-POST['name']}%' ;
}
if (isset($_POST['lastname'])) {
  $query .= AND name like binary '%{$_post['lastname']}%' ;
}
//etc etc
$query .=  order by id ASC ;
$sql = mysql_query($query) or die(mysql_error());


-- 
David Robley

Only cosmetologists give make-up exams.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Re: Multi search function (help)

2004-05-26 Thread Ross Honniball
I'm not 100% sure, but you may want to also check if the field is empty 
(using empty() function) before including in your search. (in addition to 
isset)

Also, just a caution, you will need to take some care in figuring when and 
where to place your 'and' statements linking the various parts of the query.

At 08:01 AM 27/05/2004, you wrote:
Nabil wrote:
 David Robley [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 Nabil wrote:

   hi all
 
  Is there a way to condition your search:
 
  -I have a form for four text boxes for search my Mysql...
  -I don't want to write 4 conditions and for SQL statements incase he
  decided not to search with all keywords (fields)
  - I have by example : name, lastname , nickname and phone  form...
  I need a way to select my records even one or more field were null
  (searching only on of the above)
 
  because the following SQL will generate null result
 
 
  $name=$_POST['naame'];
  $lastname=$_POST['lastname'];
  $nickname=$_POST['nickname'];
  $m_date=$_POST['m_dateY'];
  echo $name.$lastname.$nickname.$m_date;
 
  SELECT id, name , lastname , m_date from users
  where
  name like binary '%$name%' and lastname like binary '%$lastname%'  and
  nickname like binary  '%$nickname%' and m_date= YEAR('$m_date')  order
 by
  id ASC ) or die(mysql_error());
 
 
 
  Thanks in advanced

 Use isset to test whether the POST values are set and only include in the
 query if there is a value.
 thanks .. but my question is not for isset... i m thinking consider that i
 have 10 search fields... if i have to do a combination then i need a day
 to right the various SQL statements
So do something like:
$query = SELECT id, name , lastname , m_date from users where 1 ;
if (isset($_POST['name'])) {
  $query .= AND name like binary '%{$-POST['name']}%' ;
}
if (isset($_POST['lastname'])) {
  $query .= AND name like binary '%{$_post['lastname']}%' ;
}
//etc etc
$query .=  order by id ASC ;
$sql = mysql_query($query) or die(mysql_error());
--
David Robley
Only cosmetologists give make-up exams.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
.
. Ross Honniball. JCU Bookshop Cairns, Qld, Australia.
.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php