0

I'm getting excessive rows selected from the db. However, when i try to filter the data with AND lt_num it does not select anything at all. What could be the problem?

$w = $_POST['pal_num'];
$w = "'".implode("','",$_POST['pal_num'])."'";
$r = mysql_query("SELECT * FROM pl_tab WHERE pal_num AND lt_num in (".$weights.");");
SweetJC
  • 15
  • 1
  • 7

1 Answers1

0

My guess is you need to do two comparisons like this:

SELECT 
    * 
FROM 
    pl_tab 
WHERE 
    pal_num in (".$weights.")
    AND lt_num in (".$weights.");

You can't say column1 and column2 = 3 for example. If you want rows where both are equal to 3, you would need to use column1=3 and column2=3 in your query.

Also, you might want to have a read of this Q&A that I wrote a while back which covers off a lot of basic SQL queries and expands from there.

Edit:

If you have $weights in the query, you do set it somewhere, or do you want it to be what is in your variables you show here:

$weights = $_POST['pal_num'];
$weights = "'".implode("','",$_POST['pal_num'])."'";

Is this what you meant?

Community
  • 1
  • 1
Fluffeh
  • 33,228
  • 16
  • 67
  • 80
  • I changed it to `("SELECT * FROM pl_tab WHERE pal_num in (".$weights.") AND lt_num in (".$weights.");");` and it still doesn't work. Did i miss anything? Thank you for link, I definitely should read it. – SweetJC Sep 01 '13 at 06:02
  • yeah, that's what i meant. `$weights`, not `$w` – SweetJC Sep 01 '13 at 06:07