RE: [PHP] Re: Help: Database Search

2004-11-13 Thread Stuart Felenstein
I think I'm almost there :)
Only right now I'm getting an error message:

Query failed: You have an error in your SQL syntax.
Check the manual that corresponds to your MySQL server
version for the right syntax to use near '' at line 3

?php
$where = array();
$Ind = ;
$Ind = $_POST['Ind'];
  if (count($Ind)  1)
  {
$IndStr = implode(',', $Ind);
$where[] = VendorJobs.Industry IN($IndStr);
  }else{
$where[] = VendorJobs.Industry = {$Ind[0]};
}
?
?php
$sql = 'SELECT PostStart, JobTitle, Industry,
LocationState, VendorID
FROM VendorJobs
WHERE ' . implode( ' AND ', $where );

$result = mysql_query($sql) or die (Query failed: 
.mysql_error());
while($row = mysql_fetch_assoc($result))

I can't find the problem.
Anyone see anything ?

Thank you.
Stuart

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



RE: [PHP] Re: Help: Database Search

2004-11-13 Thread Stuart Felenstein
Sorry, I fixed Ind , since the element is named Ind[].
Now I get a different error:

Query failed: You have an error in your SQL syntax.
Check the manual that corresponds to your MySQL server
version for the right syntax to use near
'','','Array)' at line 3
 
 ?php
 $where = array();
 $Ind[] = ;
 $Ind[] = $_POST['Ind'];
   if (count($Ind)  1)
   {
 $IndStr = implode(',', $Ind);
 $where[] = VendorJobs.Industry IN($IndStr);
   }else{
 $where[] = VendorJobs.Industry = {$Ind[0]};
 }
 ?
 ?php
 $sql = 'SELECT PostStart, JobTitle, Industry,
 LocationState, VendorID
 FROM VendorJobs
 WHERE ' . implode( ' AND ', $where );
 
 $result = mysql_query($sql) or die (Query failed: 
 .mysql_error());
 while($row = mysql_fetch_assoc($result))
 
 I can't find the problem.
 Anyone see anything ?
 
 Thank you.
 Stuart
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 

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



Re: [PHP] Re: Help: Database Search

2004-11-13 Thread Jason Wong
On Saturday 13 November 2004 20:41, Stuart Felenstein wrote:
 Sorry, I fixed Ind , since the element is named Ind[].
 Now I get a different error:

 Query failed: You have an error in your SQL syntax.
 Check the manual that corresponds to your MySQL server
 version for the right syntax to use near
 '','','Array)' at line 3

  ?php
  $where = array();
  $Ind[] = ;
  $Ind[] = $_POST['Ind'];
if (count($Ind)  1)
{
  $IndStr = implode(',', $Ind);
  $where[] = VendorJobs.Industry IN($IndStr);
}else{
  $where[] = VendorJobs.Industry = {$Ind[0]};
  }
  ?
  ?php
  $sql = 'SELECT PostStart, JobTitle, Industry,
  LocationState, VendorID
  FROM VendorJobs
  WHERE ' . implode( ' AND ', $where );
 
  $result = mysql_query($sql) or die (Query failed: 
  .mysql_error());
  while($row = mysql_fetch_assoc($result))
 
  I can't find the problem.
  Anyone see anything ?

Uhmm, you could try some debugging of your own instead of relying on the list. 
Liberally douse your code with print_r() and var_dump() of all your important 
variables. Do they contain what you expected? If not try and figure out why 
not.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Soap and education are not as sudden as a massacre, but they are more
deadly in the long run.
-- Mark Twain
*/

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



Re: [PHP] Re: Help: Database Search

2004-11-13 Thread Stuart Felenstein

--- Jason Wong [EMAIL PROTECTED] wrote:
 
 Uhmm, you could try some debugging of your own
 instead of relying on the list. 
 Liberally douse your code with print_r() and
 var_dump() of all your important 
 variables. Do they contain what you expected? If not
 try and figure out why 
 not.
 
 -- 
 Jason Wong - Gremlins Associates -

Okay, took your advice, but it seems to be a sql error
as the message says.  

Stuart

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



Re: [PHP] Re: Help: Database Search

2004-11-13 Thread Jason Wong
On Saturday 13 November 2004 21:10, Stuart Felenstein wrote:

 Okay, took your advice, but it seems to be a sql error
 as the message says.

  Query failed: You have an error in your SQL syntax.
  Check the manual that corresponds to your MySQL server
  version for the right syntax to use near
  '','','Array)' at line 3

Yes, that was apparent from your previous post. So did you print out your 
query and examine it for any obvious mistakes? And if you couldn't spot any 
obvious mistakes then the least you could have done was to copy and paste the 
full query in your post so that we could see it in all its glory instead of 
the truncated query that was posted as part of the mysql error message. 
Please help us to help you.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Wagner's music is better than it sounds.
  -- Mark Twain
*/

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



Re: [PHP] Re: Help: Database Search

2004-11-13 Thread Stuart Felenstein

--- Jason Wong [EMAIL PROTECTED] wrote:
 Yes, that was apparent from your previous post. So
 did you print out your 
 query and examine it for any obvious mistakes? And
 if you couldn't spot any 
 obvious mistakes then the least you could have done
 was to copy and paste the 
 full query in your post so that we could see it in
 all its glory instead of 
 the truncated query that was posted as part of the
 mysql error message. 
 Please help us to help you.
 
 -- 
 Jason Wong - Gremlins Associates -

It was not apparent whatsoever.  Let me show the code
again , but I'll include the print_r returns inline
code.

?php
$where = array();
$Ind[] = ;
print_r($Ind);
//Array ( [0] = 1 [1] = 2 [2] = 3 [3] = 4 [4] = 5
[5] = 6 [6] = 7 [7] = 8 [8] = 9 [9] = 10 [10] =
11 [11] = 12 [12] = 13 [13] = 14 [14] = 15 [15] =
16 [16] = 17 [17] = 18 [18] = 19 [19] = 20 [20] =
21 [21] = 22 [22] = 23 [23] = 24 [24] = 25 [25] =
26 [26] = 27 [27] = 28 [28] = 35 [29] = [30] =
Array ( [0] = 1 [1] = 2 [2] = 3 [3] = 4 [4] = 5
[5] = 6 [6] = 7 [7] = 8 [8] = 9 [9] = 10 [10] =
11 [11] = 12 [12] = 13 [13] = 14 [14] = 15 [15] =
16 [16] = 17 [17] = 18 [18] = 19 [19] = 20 [20] =
21 [21] = 22 [22] = 23 [23] = 24 [24] = 25 [25] =
26 [26] = 27 [27] = 28 [28] = 35 ) )
So maybe this is weird, since it seems to print out
twice ?


  if (count($Ind)  0)
  {
$IndStr = implode(',', $Ind);
$where[] = VendorJobs.Industry IN($IndStr);
  }else{
$where[] = VendorJobs.Industry = {$Ind[0]};
}
?

?php
$sql = 'SELECT PostStart, JobTitle, Industry,
LocationState, VendorID
FROM VendorJobs
WHERE ' . implode( ' AND ', $where );
print_r($where);
//Array ( [0] = VendorJobs.Industry
IN(1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','35','','Array)
)

$result = mysql_query($sql) or die (Query failed: 
.mysql_error());
while($row = mysql_fetch_assoc($result))
?

Stuart

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



Re: [PHP] Re: Help: Database Search

2004-11-13 Thread Jason Wong
On Saturday 13 November 2004 21:31, Stuart Felenstein wrote:

 It was not apparent whatsoever.  Let me show the code
 again , but I'll include the print_r returns inline
 code.

 ?php
 $where = array();
 $Ind[] = ;

Not sure why you're adding an empty element to $Ind?

 print_r($Ind);
 //Array ( [0] = 1 [1] = 2 [2] = 3 [3] = 4 [4] = 5
 [5] = 6 [6] = 7 [7] = 8 [8] = 9 [9] = 10 [10] =
 11 [11] = 12 [12] = 13 [13] = 14 [14] = 15 [15] =
 16 [16] = 17 [17] = 18 [18] = 19 [19] = 20 [20] =
 21 [21] = 22 [22] = 23 [23] = 24 [24] = 25 [25] =
 26 [26] = 27 [27] = 28 [28] = 35 [29] = [30] =
 Array ( [0] = 1 [1] = 2 [2] = 3 [3] = 4 [4] = 5
 [5] = 6 [6] = 7 [7] = 8 [8] = 9 [9] = 10 [10] =
 11 [11] = 12 [12] = 13 [13] = 14 [14] = 15 [15] =
 16 [16] = 17 [17] = 18 [18] = 19 [19] = 20 [20] =
 21 [21] = 22 [22] = 23 [23] = 24 [24] = 25 [25] =
 26 [26] = 27 [27] = 28 [28] = 35 ) )
 So maybe this is weird, since it seems to print out
 twice ?

Look at it carefully, you've got a multi-dimensional array. Element [30] 
contains an array (see below). Here's a tip, when using print_r(), wrap a 
pre tag around it:

  echo pre;  // you may want to consider creating a 
  print_r($var); // function for this
  echo /pre;

That way you can see clearly the structure of any array that you print.

 IN(1','2','3',

See that the 1 has a missing quote?

 ,'27','28','35','','Array) )

See the Array (also missing a single-quote), that's element [30] mentioned 
above.

Summary: the missing single-quotes are the show-stopper.

When I said ...

  was to copy and paste the
  full query in your post so that we could see it in

... I meant post the full query that you are sending off the the DB, which in 
this case is the contents of $sql:

 $result = mysql_query($sql) or die (Query failed: 

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
I am ... a woman ... and ... technically a parasitic uterine growth
-- Sean Doran the Younger [allegedly]
ll
*/

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



Re: [PHP] Re: Help: Database Search

2004-11-13 Thread James Kaufman
Stuart,

On Sat, Nov 13, 2004 at 05:31:06AM -0800, Stuart Felenstein wrote:
 
 It was not apparent whatsoever.  Let me show the code
 again , but I'll include the print_r returns inline
 code.
 
 ?php
 $sql = 'SELECT PostStart, JobTitle, Industry,
 LocationState, VendorID
 FROM VendorJobs
 WHERE ' . implode( ' AND ', $where );
 print_r($where);
 //Array ( [0] = VendorJobs.Industry
 IN(1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','35','','Array)
 )
 

Right here, print the contents of $sql. That is the most important thing to
know right now.

 $result = mysql_query($sql) or die (Query failed: 
 .mysql_error());
 while($row = mysql_fetch_assoc($result))
 ?
 
 Stuart
 

-- 
Jim Kaufman
Linux Evangelist
public key 0x6D802619
---
A dog teaches a boy fidelity, perseverance, and to turn around three
times before lying down.
-- Robert Benchley

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



Re: [PHP] Re: Help: Database Search

2004-11-13 Thread Stuart Felenstein

--- Jason Wong [EMAIL PROTECTED] wrote:
 
 See the Array (also missing a single-quote),
 that's element [30] mentioned 
 above.
 
 Summary: the missing single-quotes are the
 show-stopper.
 
I see that , but I'm not sure how that is happening. 

Here is the sql:

$sql = 'SELECT PostStart, JobTitle, Industry,
LocationState, VendorID
FROM VendorJobs
WHERE ' . implode( ' AND ', $where );
// Is it the Where statement maybe ?

//print_r($where);

$result = mysql_query($sql) or die (Query failed: 
.mysql_error());
while($row = mysql_fetch_assoc($result))

Stuart

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



Re: [PHP] Re: Help: Database Search

2004-11-13 Thread Stuart Felenstein

--- James Kaufman [EMAIL PROTECTED]
wrote:


 Right here, print the contents of $sql. That is the
 most important thing to
 know right now.
 

SELECT PostStart, JobTitle, Industry, LocationState,
VendorID FROM VendorJobs WHERE VendorJobs.Industry
IN(1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','Array)Query
failed: You have an error in your SQL syntax. Check
the manual that corresponds to your MySQL server
version for the right syntax to use near
'','2','3','4','5','6','7','8','9','10','11','12','13','14','15'


Looks like the array is matching ?

Stuart

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



Re: [PHP] Re: Help: Database Search

2004-11-13 Thread Jason Wong
On Saturday 13 November 2004 22:14, Stuart Felenstein wrote:

  Summary: the missing single-quotes are the
  show-stopper.

 I see that , but I'm not sure how that is happening.

 Here is the sql:

 $sql = 'SELECT PostStart, JobTitle, Industry,
 LocationState, VendorID
 FROM VendorJobs
 WHERE ' . implode( ' AND ', $where );
 // Is it the Where statement maybe ?

OK, so $sql is built from $where, and what is $where built from? And so on. 
trace back up through your code examining each variable assignment.

May I remind you of this very useful advice:

http://marc.theaimsgroup.com/?l=php-generalm=109956779311140w=2

Yes debugging is tedious but someone has to do it. Or alternatively:

 - write bug free code (not even Bill Gates can do that)
 - pay someone to debug it for you (my going rate is HKD600/hour)

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Maternity pay? Now every Tom, Dick and Harry will get pregnant.
  -- Malcolm Smith
*/

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



RE: [PHP] Re: Help: Database Search

2004-11-13 Thread Graham Cossey
Hi Stuart

Not sure what's happening with the $Ind variable, maybe check the $_POST
array as you enter the script to ensure that the form is passing the data
correctly. It is almost as if you are appending it to itself at some point.
You don't have a line like this anywhere do you : $Ind[] = $Ind;  OR maybe 2
of: $Ind[] = $_POST['Ind']; ??

Part of the problem is with the implode statement. It is this that is not
adding the initial and final ' to your IN statement, see below:

  if (count($Ind)  0)
  {

$IndStr = implode(',', $Ind);
$where[] = VendorJobs.Industry IN('$IndStr');
   ^---^
  }else{
$where[] = VendorJobs.Industry = {$Ind[0]};
}

I would also remove this line:
$Ind[] = ;

HTH
Graham

 -Original Message-
 From: Stuart Felenstein [mailto:[EMAIL PROTECTED]
 Sent: 13 November 2004 13:31
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] Re: Help: Database Search



 --- Jason Wong [EMAIL PROTECTED] wrote:
  Yes, that was apparent from your previous post. So
  did you print out your
  query and examine it for any obvious mistakes? And
  if you couldn't spot any
  obvious mistakes then the least you could have done
  was to copy and paste the
  full query in your post so that we could see it in
  all its glory instead of
  the truncated query that was posted as part of the
  mysql error message.
  Please help us to help you.
 
  --
  Jason Wong - Gremlins Associates -

 It was not apparent whatsoever.  Let me show the code
 again , but I'll include the print_r returns inline
 code.

 ?php
 $where = array();
 $Ind[] = ;
 print_r($Ind);
 //Array ( [0] = 1 [1] = 2 [2] = 3 [3] = 4 [4] = 5
 [5] = 6 [6] = 7 [7] = 8 [8] = 9 [9] = 10 [10] =
 11 [11] = 12 [12] = 13 [13] = 14 [14] = 15 [15] =
 16 [16] = 17 [17] = 18 [18] = 19 [19] = 20 [20] =
 21 [21] = 22 [22] = 23 [23] = 24 [24] = 25 [25] =
 26 [26] = 27 [27] = 28 [28] = 35 [29] = [30] =
 Array ( [0] = 1 [1] = 2 [2] = 3 [3] = 4 [4] = 5
 [5] = 6 [6] = 7 [7] = 8 [8] = 9 [9] = 10 [10] =
 11 [11] = 12 [12] = 13 [13] = 14 [14] = 15 [15] =
 16 [16] = 17 [17] = 18 [18] = 19 [19] = 20 [20] =
 21 [21] = 22 [22] = 23 [23] = 24 [24] = 25 [25] =
 26 [26] = 27 [27] = 28 [28] = 35 ) )
 So maybe this is weird, since it seems to print out
 twice ?


   if (count($Ind)  0)
   {
 $IndStr = implode(',', $Ind);
 $where[] = VendorJobs.Industry IN($IndStr);
   }else{
 $where[] = VendorJobs.Industry = {$Ind[0]};
 }
 ?

 ?php
 $sql = 'SELECT PostStart, JobTitle, Industry,
 LocationState, VendorID
 FROM VendorJobs
 WHERE ' . implode( ' AND ', $where );
 print_r($where);
 //Array ( [0] = VendorJobs.Industry
 IN(1','2','3','4','5','6','7','8','9','10','11','12','13','14','15
','16','17','18','19','20','21','22','23','24','25','26','27','28','35','','
Array)
 )

 $result = mysql_query($sql) or die (Query failed: 
 .mysql_error());
 while($row = mysql_fetch_assoc($result))
 ?

 Stuart

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



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



RE: [PHP] Re: Help: Database Search

2004-11-13 Thread Stuart Felenstein
--- Graham Cossey [EMAIL PROTECTED] wrote:

 Hi Stuart
 
 Not sure what's happening with the $Ind variable,
 maybe check the $_POST
 array as you enter the script to ensure that the
 form is passing the data
 correctly. It is almost as if you are appending it
 to itself at some point.
 You don't have a line like this anywhere do you :
 $Ind[] = $Ind;  OR maybe 2
 of: $Ind[] = $_POST['Ind']; ??
 
 Part of the problem is with the implode statement.
 It is this that is not
 adding the initial and final ' to your IN statement,
 see below:
 
   if (count($Ind)  0)
   {
 
 $IndStr = implode(',', $Ind);
 $where[] = VendorJobs.Industry IN('$IndStr');
^---^
   }else{
 $where[] = VendorJobs.Industry = {$Ind[0]};
 }
 
 I would also remove this line:
 $Ind[] = ;
 
 HTH
 Graham
 
I think it's working , at least I get results now with
no error messages.  Still some work to go on the
script.  Here is the current initializatin and sql
code:

$Ind = $HTTP_POST_VARS['Ind'];
if (count($Ind)  0 AND is_array($Ind)) {
$s_Ind = '.implode(',', $Ind).';
}

I guess here I should put this in braces as it should
be conditional if $Ind is set, if not the subsequent
sql statement shouldn't go in.

if ($Ind) 
$sql .=  WHERE VendorJobs.Industry IN ($s_Ind);

Stuart

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



Re: [PHP] Re: Help: Database Search

2004-11-12 Thread Stuart Felenstein

--- Sebastian Mendel [EMAIL PROTECTED] wrote:
 
 $where = array();
 
 if ( isset($_POST['Ind']) ) {
  $where[] = 'vendorjobs.Industry = ' . (int)
 $_POST['Ind'];
 }
 if ( isset($_POST['Days']) ) {
  $where[] = 'Date_Sub(Curdate(), interval ' .
 (int) $_POST['Days'] . 
 ' day) = PostStart';
 }
 
 $sql = '
   SELECT ...
 FROM vendorjobs
WHERE ' . implode( ' AND ', $where );
 
 
Sebastian, I meant to thank you for this code the
other day.  
What I'm trying to figure out is some of my elements
are arrays themselves.  So for example I have this :

$Ind = ;
$Ind = $HTTP_POST_VARS['Ind'];
if (count($Ind)  0 AND is_array($Ind)) {
 $Ind = '.implode(',', $Ind).';
}

So how would this code , or array get into what you
stated as:

 $where = array();
 
 if ( isset($_POST['Ind']) ) {
  $where[] = 'vendorjobs.Industry = ' . (int)
 $_POST['Ind'];
 }

I guess that is putting an array into an array ?
Not quite sure how the loop would go.

Thank you,
Stuart

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



RE: [PHP] Re: Help: Database Search

2004-11-12 Thread Graham Cossey

I think you're implode example is pretty close.

?php
$Ind = ;
$Ind = $_POST['Ind'];
if(is_array($Ind)
{
  if (count($Ind)  1)
  {
$IndStr = implode(',', $Ind);
$where[] = vendorjobs.Industry IN($IndStr);
  }else{
$where[] = vendorjobs.Industry = {$Ind[0]};
}else{
  // Is there an error if not an array?
}

$sql = 'SELECT ...
 FROM vendorjobs
 WHERE ' . implode( ' AND ', $where );
?

Not sure if you need the {} above, I think you do as it's an array reference
in a string.

This should result in:

WHERE vendorjobs.Industry IN (2,3,5)

OR

WHERE vendorjobs.Industry = 2

HTH
Graham



 -Original Message-
 From: Stuart Felenstein [mailto:[EMAIL PROTECTED]
 Sent: 12 November 2004 12:42
 To: Sebastian Mendel; [EMAIL PROTECTED]
 Subject: Re: [PHP] Re: Help: Database Search



 --- Sebastian Mendel [EMAIL PROTECTED] wrote:
 
  $where = array();
 
  if ( isset($_POST['Ind']) ) {
   $where[] = 'vendorjobs.Industry = ' . (int)
  $_POST['Ind'];
  }
  if ( isset($_POST['Days']) ) {
   $where[] = 'Date_Sub(Curdate(), interval ' .
  (int) $_POST['Days'] .
  ' day) = PostStart';
  }
 
  $sql = '
SELECT ...
  FROM vendorjobs
 WHERE ' . implode( ' AND ', $where );
 

 Sebastian, I meant to thank you for this code the
 other day.
 What I'm trying to figure out is some of my elements
 are arrays themselves.  So for example I have this :

 $Ind = ;
 $Ind = $HTTP_POST_VARS['Ind'];
 if (count($Ind)  0 AND is_array($Ind)) {
  $Ind = '.implode(',', $Ind).';
 }

 So how would this code , or array get into what you
 stated as:

  $where = array();
 
  if ( isset($_POST['Ind']) ) {
   $where[] = 'vendorjobs.Industry = ' . (int)
  $_POST['Ind'];
  }

 I guess that is putting an array into an array ?
 Not quite sure how the loop would go.

 Thank you,
 Stuart

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



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



RE: [PHP] Re: Help: Database Search

2004-11-12 Thread Stuart Felenstein

--- Graham Cossey [EMAIL PROTECTED] wrote:

 This should result in:
 
 WHERE vendorjobs.Industry IN (2,3,5)
 
 OR
 
 WHERE vendorjobs.Industry = 2
 
 HTH
 Graham

Not sure what you mean by the above ?

Stuart

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



RE: [PHP] Re: Help: Database Search

2004-11-12 Thread Graham Cossey
What I meant was that the $sql variable should contain
a where clause of WHERE vendorjobs.Industry IN (2,3,5)
if you had a multi-element array or WHERE vendorjobs.Industry 
= 2 if you had a single-element array.

The IN statement is easier to construct than multiple ORs and
tends to run faster as well.

Graham

 -Original Message-
 From: Stuart Felenstein [mailto:[EMAIL PROTECTED]
 Sent: 12 November 2004 14:13
 To: Graham Cossey; Sebastian Mendel; [EMAIL PROTECTED]
 Subject: RE: [PHP] Re: Help: Database Search 
 
 
 
 --- Graham Cossey [EMAIL PROTECTED] wrote:
 
  This should result in:
  
  WHERE vendorjobs.Industry IN (2,3,5)
  
  OR
  
  WHERE vendorjobs.Industry = 2
  
  HTH
  Graham
 
 Not sure what you mean by the above ?
 
 Stuart
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 

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



[PHP] Re: Help: Database Search

2004-11-10 Thread Sebastian Mendel
Stuart Felenstein wrote:
I am creating a database search form and results.
Running into a problem though.
I have two form elements, both that are fed by tables
that have int values (1, 2 , etc)
my sql statement is such:
SELECT vendorjobs.PostStart, vendorjobs.JobTitle,
vendorjobs.Industry, vendorjobs.VendorID,
vendorjobs.LocationCity, vendorjobs.TaxTerm FROM
vendorjobs WHERE vendorjobs.Industry = '$Ind' AND
Date_Sub(Curdate(), interval '$Days' day) = PostStart

But if the user decides to only use one of the
elements, then I don't want the query to return
nothing because of the And in the where clause so I
have these 2 statements that set a default value
(shown here as 0 in the event one of the two elements
aren't selected:  (Having no luck as the form still
only works correctly if I've set both elements)
$Ind = 0;
if (isset($_POST['Ind'])) {
  $Ind = (get_magic_quotes_gpc()) ? $_POST['Ind'] :
addslashes($_POST['Ind']);
}
$Days = 0;
if (isset($_POST['Days'])) {
  $Days = (get_magic_quotes_gpc()) ? $_POST['Days'] :
addslashes($_POST['Days']);
$where = array();
if ( isset($_POST['Ind']) ) {
$where[] = 'vendorjobs.Industry = ' . (int) $_POST['Ind'];
}
if ( isset($_POST['Days']) ) {
$where[] = 'Date_Sub(Curdate(), interval ' . (int) $_POST['Days'] . 
' day) = PostStart';
}

$sql = '
 SELECT ...
   FROM vendorjobs
  WHERE ' . implode( ' AND ', $where );
--
Sebastian Mendel
www.sebastianmendel.de www.warzonez.de www.tekkno4u.de www.nofetish.com
www.sf.net/projects/phpdatetimewww.sf.net/projects/phptimesheet
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php