Warning: mysql_fetch_assoc(): supplied argument is not a val
Moderator: General Moderators
Hello,
OK, do you mean like this: ? When I tried that it still didn't echo anything. Was it that you ment? And/or is there anything else I should change?
Best Regards
Oskar R
OK, do you mean like this:
Code: Select all
'".$item_amount."'Best Regards
Oskar R
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)
but you have: 'kare' LIKE '%oskare100%' -> false
Hello,
Best Regards
Oskar R
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
Best Regards
Oskar R
I mean you need to understand how LIKE works.
Please explain LIKE in your own words. See http://dev.mysql.com/doc/refman/5.1/en/ ... tions.html
Please explain LIKE in your own words. See http://dev.mysql.com/doc/refman/5.1/en/ ... tions.html
Hello,
OK, now I've really tried to fix this but I couldn't come longer than this;
And that echos this;
So I guess that's good? Because it was from the beginning "Templates, test, ebooks" but now "Templates" "test" "ebooks" and from what I understand I needed to do that for the LIKE function to function as it should.
The thing I can figure out is how to get a working MySQL querey of that, I've tried but it doesn't work... Here is one, among many others, that I've tried with;
So could you please help me with the querey? Or at least tell me what to do? I would ge really greatful if you could.. Thanks in advance,
Best Regards
Oskar R
OK, now I've really tried to fix this but I couldn't come longer than this;
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 ebooksThe thing I can figure out is how to get a working MySQL querey of that, I've tried but it doesn't work... Here is one, among many others, that I've tried with;
Code: 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]."%'))"Best Regards
Oskar R
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);