Jump to content

Inner Join of six tables query not running from php form?


Recommended Posts

"SELECT candidate.first_name, candidate.last_name, user.first_name, user.last_name, client.city, candidate_joborder_status.short_description, client.name FROM user INNER JOIN (( client INNER JOIN (( candidate INNER JOIN candidate_joborder ON candidate.candidate_id = candidate_joborder.candidate_id ) INNER JOIN joborder ON candidate_joborder.candidate_joborder_id = joborder.joborder_id ) ON client.client_id = joborder.client_id ) INNER JOIN candidate_joborder_status ON candidate_joborder.status = candidate_joborder_status.candidate_joborder_status_id) ON user.user_id = candidate.entered_by WHERE ( ( ( user.user_id ) = 1257 ) ) LIMIT 0, 30 ; ";

 

Above mentioned is my query used  INNER Join with six tables. This query run at phpmyadmin perfectly but when i try to run this into php and get data into html format then give an error. Please check query if there is any wrong in code.

 

Regards

JIMI

I am getting error as below:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL

 

Also getting query which i am not using for data.

 

""SELECT candidate . first_name , candidate . last_name , user . first_name , user . last_name , client . city , candidate_joborder_status . short_description , client . name ' . ' FROM user INNER JOIN ( ( client INNER JOIN ( ( candidate INNER JOIN candidate_joborder ON candidate . candidate_id = candidate_joborder . candidate_id ) INNER JOIN joborder ON candidate_joborder . candidate_joborder_id = joborder . joborder_id ) ON client . client_id = joborder . client_id ) INNER JOIN candidate_joborder_status ON candidate_joborder . status = candidate_joborder_status . candidate_joborder_status_id ) ON user . user_id = candidate . entered_by ' . ' WHERE ( ( ( user . user_id ) = '" .$_POST['from']. "' ) ) LIMIT 0, 30 ; ";"

 

Not getting what problem with my code. Hope solve as soon as possible.

Please need you people help to solve this issue.

 

JIMI

Post the entire code block.

 

You should have something like:

 

$query = "SELECT column FROM table WHERE condition IS TRUE LIMIT 1";
$result = mysql_query($query);
$record = mysql_fetch_array($result);

 

Placing the query string where the result identifier variable is supposed to be would produce an error similar to what you have discribed.

The ";" won't give an error, but it isn't necessary unless

- running query from mysql command line

- it's a query inside a sql script with mulyiple queries

 

Always check mysql_error when you use mysql_query.

 

Try rearranging it,

 

<?php
$query = "SELECT candidate.first_name, candidate.last_name, user.first_name, user.last_name, 
        client.city, candidate_joborder_status.short_description, client.name
FROM user
    INNER JOIN candidate ON user.user_id = candidate.entered_by
    INNER JOIN candidate_joborder ON candidate.candidate_id = candidate_joborder.candidate_id
    INNER JOIN joborder ON candidate_joborder.candidate_joborder_id = joborder.joborder_id
    INNER JOIN client ON client.client_id = joborder.client_id  
    INNER JOIN candidate_joborder_status ON candidate_joborder.status = candidate_joborder_status.candidate_joborder_status_id
WHERE user.user_id  = 1257
LIMIT 0, 30";

$res = mysql_query($query) or die (mysql_error());
?>

 

Personally, I think it's more legible if aliases are used, eg

<?php
$query = "SELECT c.first_name, c.last_name, u.first_name, u.last_name, 
        cl.city, js.short_description, cl.name
FROM user u
    INNER JOIN candidate c 
        ON u.user_id = c.entered_by
    INNER JOIN candidate_joborder cj 
        ON c.candidate_id = cj.candidate_id
    INNER JOIN joborder j 
        ON cj.candidate_joborder_id = j.joborder_id
    INNER JOIN client cl 
        ON cl.client_id = j.client_id  
    INNER JOIN candidate_joborder_status js 
        ON cj.status = js.candidate_joborder_status_id
WHERE u.user_id  = 1257
LIMIT 0, 30";
?>

 

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.