Jump to content

PHP/MySQL Help


dmcdaniel

Recommended Posts

I am having a problem with my PHP/MySQL coding and I can not figure out what I am doing wrong.

 

I have two tables in a database. One called EmployeeInfo and another called Absence. In the Employee Info table, I have two employees, Derek and Adrian. In the Absence table, I have two records, One for Derek and Adrian.

 

Goal: Using PHP/MySQL, I want to call upon an employee using a form and display that person's absence. The form pulls up correctly.

 

If I do NOT put a WHERE clause into my SQL statement, it pulls up all the absences perfectly fine. Once I put in the WHERE = EmployeeInfo.Name = 'NameSelect' then it fails every time. Here is my SQL Coding:

$result = mysql_query("SELECT * FROM Absence LEFT JOIN EmployeeInfo ON(Absence.Account = EmployeeInfo.Account) WHERE EmployeeInfo.Name='NameSelect'");

 

Any help is greatly appreciated.

 

Link to comment
Share on other sites

here is a sample of a left join that i use with a where clause, and other stuff too.

 

$sql = "SELECT SQL_CALC_FOUND_ROWS cust.id, cust.f_name, cust.l_name, 
							cust.email, cust.password, cust.optin, cust.status, o.c_id, d.d_id, 
							COUNT( o.id ) AS orders_cnt, 
							COUNT( d.id ) AS deals_cnt
							FROM customers AS cust
							LEFT JOIN orders AS o ON o.c_id = cust.id
							LEFT JOIN deals AS d ON d.d_id = cust.id
							WHERE cust.l_name LIKE '".$_pid."%'
							GROUP BY o.c_id, d.d_id ORDER BY cust.l_name LIMIT ".Paginate::getCurrentIndex().", ".Paginate::getLimit();

Link to comment
Share on other sites

I tried using a LIKE statement but that didn't work either. Not sure if it is something in my view.php code from the form but I created a select query and gave it the name NameSelect so it should all be working properly. Not Sure why its not. Maybe if I pull the NameSelect into a variable.

 

I will give that a shot and see.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.