Jump to content

multiple JOIN question


speedy33417

Recommended Posts

I'm trying to normalize my database the best I can which means I end up with more complex queries. It's getting a bit too much for me and am totally lost at this point...

 

Basically I'm working on an appointment page for all employees. I'm having an issue with this specific query.

 

$sql = "SELECT job.job_id, job_employee.assign_id, job.job_status, job.job_date, job.address_id,
customer_address.cust_id, customer_address.google_address, customer.cust_firstname, customer.cust_lastname, customer.special
FROM job INNER JOIN job_employee ON (job.job_id = job_employee.job_id AND job_employee.job_id = '$prEmployeeId[$i]')
INNER JOIN customer_address ON (job.address_id = customer_address.address_id)
INNER JOIN customer ON (customer_address.customer_id = customer.cust_id)
WHERE (job.job_date >= '$weekDateLow[$d]' && job.job_date <= '$weekDateHigh[$d]') AND (job.job_status = 'D' || job.job_status = 'S') ORDER BY job.job_date";

 

I'm trying to pull information from four different tables for one specific job. Here's my table structure:

job           job_employee     customer         customer_address
-----------   ------------     -------------    ----------------
job_id        assign_id        cust_id          address_id
customer_id   job_id           cust_firstname   customer_id
address_id    employee_id      cust_lastname    google_address
job_date                       special
job_status

 

The query should pull all required information for the job from all four tables between a specific date range ($weekDateLow[$d] and $weekDateHigh[$d]) if the job_status is either 'D' or 'S' and the assigned employee is $prEmployeeId[$i].

The variables that I use in the query are all good. I used them in a more simple version.

 

I get this error Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

Link to comment
https://forums.phpfreaks.com/topic/103993-multiple-join-question/
Share on other sites

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.