Jump to content

plezzy

New Members
  • Posts

    7
  • Joined

  • Last visited

plezzy's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for the help. I appreciate your advice. im struggling to get my head around such a query. can you give a quick example of that style of query?. Im looking to show all from jobs table. show if exists message from messages table. show if exists quote from quotes table then display with no duplicates. thanks
  2. How can i stop the following returning duplicate rows? $sql = "SELECT DISTINCT jobs.job_id AS jobid, jobs.worktitle AS wrktitle, jobs.workinfo AS wrkinfo, messages.message AS msg FROM jobs LEFT JOIN messages ON jobs.job_id = messages.job_id LEFT JOIN quotes ON jobs.job_id = quotes.workid";
  3. yes. the jobs table as all the details and job id is auto increment messages table - this contains any questions asked about the job attaching via job id quotes table contains any quotes recieved against the job again via job id so in my table i wanted to show all the jobs where whatever including any messages and any quotes
  4. Thank you... but the link does not work.
  5. Thank you for some proper advice. My problem is that jobs = some job ids have messages associated via messages table(job id's) and job ids have quotes associated via quotes table(job id's) So are you saying that using a LEFT JOIN will return results even if no records are present from some tables?
  6. would it be possible to say what kind of join to use... or anything that may assist me?
  7. Hello, I am very new to both php and sql. I have 3 tables in a database jobs, messages, and quotes What is the best way to select all from jobs WHERE county=$cnty And category=$cat Then select All from messages WHERE job_id = job_id from jobs table (if there is any) Then select all from quotes WHERE job_id = job_id from jobs table (if there is any)? Im guessing that i would need to join the tables? If so can i join tables even if there is no records in one or two of the three tables? Please, any help would be great. i tried <?php if ($cnty=="All" && $cat=="All") {$sql = ("SELECT jobs.*,DATE_FORMAT(date, '%d-%m-%Y') as date,messages.*,DATE_FORMAT(date, '%d-%m-%Y') as date, quotes.* ,DATE_FORMAT(date, '%d-%m-%Y') as date FROM jobs JOIN messages ON messages.job_id = jobs.job_id JOIN quotes ON quotes.job_id = messages.job_id ORDER BY job_id DESC LIMIT $start, $limit") or die(mysql_error());} elseif ($cnty!="All" && $cat=="All") {$sql = ("SELECT jobs.*,DATE_FORMAT(date, '%d-%m-%Y') as date,messages.*,DATE_FORMAT(date, '%d-%m-%Y') as date, quotes.* ,DATE_FORMAT(date, '%d-%m-%Y') as date FROM jobs JOIN messages ON messages.job_id = jobs.job_id JOIN quotes ON quotes.job_id = messages.job_id WHERE county=$cnty ORDER BY job_id DESC LIMIT $start, $limit") or die(mysql_error());} elseif ($cnty=="All" && $category!="All") {$sql = ("SELECT jobs.*,DATE_FORMAT(date, '%d-%m-%Y') as date,messages.*,DATE_FORMAT(date, '%d-%m-%Y') as date, quotes.* ,DATE_FORMAT(date, '%d-%m-%Y') as date FROM jobs JOIN messages ON messages.job_id = jobs.job_id JOIN quotes ON quotes.job_id = messages.job_id WHERE category=$cat ORDER BY job_id DESC LIMIT $start, $limit") or die(mysql_error());} else{$sql = ("SELECT jobs.*,DATE_FORMAT(date, '%d-%m-%Y') as date,messages.*,DATE_FORMAT(date, '%d-%m-%Y') as date, quotes.* ,DATE_FORMAT(date, '%d-%m-%Y') as date FROM jobs JOIN messages ON messages.job_id = jobs.job_id JOIN quotes ON quotes.job_id = messages.job_id WHERE county=$cnty AND category=$cat ORDER BY job_id DESC LIMIT $start, $limit") or die(mysql_error());} ?> but dont know how to echo the results or if it works
×
×
  • 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.