Posted: Sun Jan 07, 2007 12:12 pm
Why did all the OR's change to AND's?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
'".$item_amount."'That takes care of the first issue but notoskare100 wrote:OK, so I should use something like;instead ofCode: Select all
AND ((`identify_pos` LIKE '%$item_title%') OR (`identify_pos2` LIKE '%$item_title%'))then? Or how should I do it?Code: Select all
AND ((`identify_pos` OR `identify_pos2`) LIKE %$item_title%)
'%kare%' LIKE 'oskare100' -> truevolka wrote:But that's still wrong, you would need something like
AND (('%ebooks%' LIKE 'Templates, test, ebooks') OR ('%templates%' LIKE 'Templates, test, ebooks') )
Either add the appropriate % characters to your records or use e.g. INSTR, see http://dev.mysql.com/doc/refman/4.1/en/ ... tions.html
Same withand the purpose ofAND ((`identify_neg` OR `identify_neg2`) NOT LIKE '%$item_title%')I do not understand at all.AND ((`identify_pos` OR `identify_pos2` OR `identify_neg` OR `identify_neg2`) != $item_title)
Because I both keywords must match, not only one of them. I though that was the way to do that.. Isn't that correct?feyd wrote:Why did all the OR's change to AND's?
I don't understand that, should I have something like '".%$item_title%."' instead or what do you mean? Should I add/remove something else?volka wrote:'%kare%' LIKE 'oskare100' -> true
but you have: 'kare' LIKE '%oskare100%' -> false
Code: Select all
$item_amount="2.95";
$item_title="Templates, test, ebooks";
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$trimmed = trim($item_title, " \t.");
$keywords = explode(",", $trimmed);
echo $keywords;
echo $keywords[0];
echo $keywords[1];
echo $keywords[2];
echo $keywords[3];Code: Select all
ArrayTemplates test ebooksCode: Select all
"SELECT * FROM `items` WHERE ((`identify_pos` LIKE '%".$keywords[0]."%' OR '%".$keywords[1]."%' OR '%".$keywords[2]."%'OR '%".$keywords[3]."%' OR '%".$keywords[4]."%' OR '%".$keywords[5]."%') AND (`identify_pos2` LIKE '%".$keywords[0]."%' OR '%".$keywords[1]."%' OR '%".$keywords[2]."%'OR '%".$keywords[3]."%' OR '%".$keywords[4]."%' OR '%".$keywords[5]."%')) AND ((`identify_neg` NOT LIKE '%".$keywords[0]."%' OR '%".$keywords[1]."%' OR '%".$keywords[2]."%'OR '%".$keywords[3]."%' OR '%".$keywords[4]."%' OR '%".$keywords[5]."%') AND (`identify_neg2` NOT LIKE '%".$keywords[0]."%' OR '%".$keywords[1]."%' OR '%".$keywords[2]."%'OR '%".$keywords[3]."%' OR '%".$keywords[4]."%' OR '%".$keywords[5]."%'))"volka wrote:Either add the appropriate % characters to your records or use e.g. INSTR, see http://dev.mysql.com/doc/refman/4.1/en/ ... tions.html
Code: Select all
<?php
$host = 'localhost';
$username = 'localuser';
$password = 'localpass';
$db_name = 'test';
$mysql = mysql_connect($host, $username, $password)or die(mysql_error());
mysql_select_db($db_name, $mysql)or die(mysql_error());
$item_amount='2.95';
$item_title= mysql_real_escape_string('Templates, test, ebooks', $mysql);
$query="SELECT
*
FROM
`items`
WHERE
`price` = $item_amount
AND ('$item_title' LIKE `identify_pos` AND '$item_title' LIKE `identify_pos2`)
AND ('$item_title' NOT LIKE `identify_neg` AND '$item_title' NOT LIKE `identify_neg2`)
";
echo 'Debug: ', $query, "</br >\n";
$result = mysql_query($query, $mysql) or die(mysql_error());
if ( false===($row=mysql_fetch_assoc($result)) ) {
echo 'no such row', $query, "<br />\n";
}
else {
echo 'item_id: ', $row['item_id'], "<br />\n";Code: Select all
--
-- Dumping data for table `items`
--
INSERT INTO `items` (`item_id`, `item_name`, `price`, `identify_pos`, `identify_pos2`, `identify_neg`, `identify_neg2`, `file_id`, `pack_id`) VALUES
(1, '15GB package', '2.95', '%15gb%', '%templates%', '%test%', '', 0, 0),
(2, 'not 15gb package', '2.95', '%ebooks%', '%templates%', '%15gb%', '', 0, 0);