Jump to content

MySQL statement error


joe1986

Recommended Posts

Hi there, Im using mysql Ver 14.12 Distrib 5.0.75 and im having a problem writing a specific statement within a php page. The code is as follows:

 

$q = "SELECT    c.id_case, c.title, c.status, c.date_creation,
                fu.*,
                a.name_first, a.name_middle, a.name_last
        FROM lcm_case as c, lcm_followup as fu, lcm_author as a, lcm_case_author as ca
        WHERE c.id_case=fu.id_case
          AND fu.id_author=a.id_author
          AND ca.id_case=fu.id_case
          AND ca.id_author=fu.id_author";

if (strlen($find_followup_string)>1) {
        // Add search criteria
        $q = "SELECT *
              FROM lcm_followup
              WHERE ((id_followup LIKE '%$find_followup_string%')
                        OR (type LIKE '%$find_followup_string%')
                        OR (description LIKE '%$find_followup_string%'))
                        AND c.id_case=fu.id_case
                        AND fu.id_author=a.id_author
                        AND ca.id_case=fu.id_case
                        AND ca.id_author=fu.id_author";

 

Sorry, there is a small amount of PHP code there, but just to demonstrate what I need. Simply, I have one SQL statement which is executed if there is no search term in a PHP search box (This runs fine), and another which is supposed to run when there is a search term present. This runs fine if I dont include the AND statements but I dont get the results I need from the other two tables. The error message I am getting is:

 

Error: Error in SQL database query.

« Unknown column 'c.id_case' in 'where clause' »

 

I am using 3 tables named, lcm_followup, lcm_case and lcm_author

Can anybody help?

Link to comment
https://forums.phpfreaks.com/topic/172130-mysql-statement-error/
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.