Help with adding to this code...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Help with adding to this code...

Post by Jonah Bron »

tattooartist wrote:I figured it out that the syntax for that string query will not work with my version of php. I changed it to
mysql_escape_string() and it went through. Since this onemysql_escape_string() is a deprecated query I figured it was my version of php being older. This old string worked but it is now getting caught up with this....
Glad you figured it out. If you can, you really should upgrade your PHP installation.
tattooartist wrote:Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/pennstateind.com/httpdocs/php_test/library_search_test.php on line 711
That sounds like the query encountered an error. It returns false if an error occures. So, lets do this. Change this line:

Code: Select all

$result=mysql_query($query);
To this:

Code: Select all

$result = mysql_query($query);
if (!$result) {
    die(mysql_error());
}
tattooartist wrote:I am so grateful for your help with this! Thank you. If it gets to be too much of a pain now worries:)
No trouble, though I appreciate the sentiment :)
tattooartist
Forum Newbie
Posts: 18
Joined: Thu Feb 17, 2011 3:59 pm

Re: Help with adding to this code...

Post by tattooartist »

Thanks again. I got this error this time around.


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 'product_name LIKE='%SLIMLINE%'' at line 5


:banghead:
tattooartist
Forum Newbie
Posts: 18
Joined: Thu Feb 17, 2011 3:59 pm

Re: Help with adding to this code...

Post by tattooartist »

This is what it says in my phpMyadmin if this helps...

phpMyAdmin 2.6.0-pl3

MySQL 4.1.21
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Help with adding to this code...

Post by Jonah Bron »

Oops, this should fix it.

Code: Select all

    $query = 'SELECT *
    FROM category c
    INNER JOIN library l ON c.category_id = l.category_id
    INNER JOIN files f ON l.file_id = f.file_id
    WHERE product_name LIKE = "%' . $find . '%"';
tattooartist
Forum Newbie
Posts: 18
Joined: Thu Feb 17, 2011 3:59 pm

Re: Help with adding to this code...

Post by tattooartist »

It did not like the = for some reason. was getting another error. I removed it and walla! How can I repay you?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Help with adding to this code...

Post by Jonah Bron »

Oh yeah, of course. So everything works now? I visited the page and I get an error.
tattooartist wrote:I removed it and walla!
For future reference, "walla" is spelled "voilà" ;)
tattooartist
Forum Newbie
Posts: 18
Joined: Thu Feb 17, 2011 3:59 pm

Re: Help with adding to this code...

Post by tattooartist »

Yes everything is working great on the page. New location is www.pennstateind.com/php_test/library2.php

Sorry about that
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Help with adding to this code...

Post by Jonah Bron »

Great. But note, it won't work for separated multi-word searches. For example, if the user searches for "black enamel", "PK-PCLA2B: Slimline Black Enamel Pencil Kit" will come up (along with many others). But if he searches for "slimline pencil", no results will come up. Is this acceptable?
tattooartist
Forum Newbie
Posts: 18
Joined: Thu Feb 17, 2011 3:59 pm

Re: Help with adding to this code...

Post by tattooartist »

That will be fine. Thank you again!
Post Reply