Jump to content

Inner join is not displaying in php


Ivan007

Recommended Posts

Quote

 

 $stmt = $pdo->query("SELECT tblseeker.First_Name,tblseeker.Last_Name,

                                    tblseeker.Phone_No,tblseeker.Tel_No,Email,Address,

                                    tblqualification.Qualification_type,tbllocation.District,Job_Preference,

                                    tbljobcategory.Category,tblcontracttype.Contract_type,Seeker_pic,status_id

                                    from tblseeker

                                    INNER JOIN tblqualification on  tblseeker.qualification_id=tblqualification.Qualifi_id              

                                    INNER join tbllocation  on tblseeker.State=tbllocation.Location_ID

                                    INNER JOIN tbljobcategory on tblseeker.category_id= tbljobcategory.category_id

                                    INNER JOIN tblcontracttype on tblseeker.contract_id =tblcontracttype.contract_id

                                    where tblseeker.First_Name='$txtfname' or tblseeker.Last_Name='$txtlname'

                                    or tblseeker.Phone_No='$txtpnum' or tblseeker.Tel_No='$txttel'or

                                    tblqualification.Qualification_type='$txtquali'

                                    or

                                    tbllocation.District='$txtlocation'

                                    or tbljobcategory.Category='$txtcategory'

                                    or tblcontracttype.Contract_type='$txtcontract';");

                             //here the data output when I used var dump

                                                        while($rows = $stmt->fetch(PDO::FETCH_ASSOC)){

                                                           //at this point nothing is output

                                                            echo ("<tr>");

                                                            echo "<td>". htmlentities($rows['First_Name']) ."</td>";

                                                            echo "<td>". htmlentities($rows['Last_Name']) ."</td>";

                                                            echo "<td>". htmlentities($rows['Phone_No']) ."</td>";

                                                            echo "<td>". htmlentities($rows['Tel_No']) ."</td>";

                                                            echo "<td>". htmlentities($rows['Email']) ."</td>";

                                                            echo "<td>". htmlentities($rows['Address']) ."</td>";

                                                            echo "<td>". htmlentities($rows['District']) ."</td>";

                                                            echo "<td>". htmlentities($rows['Job_Preference']) ."</td>";

                                                            echo "<td>". htmlentities($rows['Qualification_type']) ."</td>";

                                                            echo "<td>". htmlentities($rows['Category']) ."</td>";

                                                            echo "<td>". htmlentities($rows['Contract_type']) ."</td>";

Link to comment
Share on other sites

when I var_dump($stmt) I got the right result but nothing is output at this stage

 while($rows = $stmt->fetch(PDO::FETCH_ASSOC)){

                                                           //at this point nothing is output

                                                            echo ("<tr>");

                                                            echo "<td>". htmlentities($rows['First_Name']) ."</td>";

                                                            echo "<td>". htmlentities($rows['Last_Name']) ."</td>";

                                                            echo "<td>". htmlentities($rows['Phone_No']) ."</td>";

                                                            echo "<td>". htmlentities($rows['Tel_No']) ."</td>";

                                                            echo "<td>". htmlentities($rows['Email']) ."</td>";

                                                            echo "<td>". htmlentities($rows['Address']) ."</td>";

                                                            echo "<td>". htmlentities($rows['District']) ."</td>";

                                                            echo "<td>". htmlentities($rows['Job_Preference']) ."</td>";

                                                            echo "<td>". htmlentities($rows['Qualification_type']) ."</td>";

                                                            echo "<td>". htmlentities($rows['Category']) ."</td>";

                                                            echo "<td>". htmlentities($rows['Contract_type']) ."</td>";

Link to comment
Share on other sites

41 minutes ago, Ivan007 said:

when I var_dump($stmt) I got the right result but nothing is output at this stage

and what is the right result?

if it displayed the sql query string, and not a false or null value, all that means is that the query didn't fail with an error. it doesn't mean that the query matched any rows of data.

Link to comment
Share on other sites

 

object(PDOStatement)#6 (1) { ["queryString"]=> string(1422) "SELECT tblseeker.First_Name,tblseeker.Last_Name, tblseeker.Phone_No,tblseeker.Tel_No,Email,Address, tblqualification.Qualification_type,tbllocation.District,Job_Preference, tbljobcategory.Category,tblcontracttype.Contract_type,Seeker_pic,status_id from tblseeker INNER JOIN tblqualification on tblseeker.qualification_id=tblqualification.Qualifi_id INNER join tbllocation on tblseeker.State=tbllocation.Location_ID INNER JOIN tbljobcategory on tblseeker.category_id= tbljobcategory.category_id INNER JOIN tblcontracttype on tblseeker.contract_id =tblcontracttype.contract_id where tblseeker.First_Name='ivan' or tblseeker.Last_Name='' or tblseeker.Phone_No='' or tblseeker.Tel_No=''or tblqualification.Qualification_type='Choose...' or tbllocation.District='Choose...' or tbljobcategory.Category='Choose...' or tblcontracttype.Contract_type='Choose...';" }

 

I got this value when using var_dump($stmt)

Link to comment
Share on other sites

A var dump of the object simply shows you the query, no results.  Are you checking for how many rows were returned? 

PS - when you write a query you can use an alias for the table name such as  just a 't' instead of the whole table name.  Saves an awful lot of typing.

Ex.

$q = select t.field1, t.field2, t.field3 from tablename t where t.id='abc'";

 

 

Edited by ginerjm
Link to comment
Share on other sites

BTW - do you really expect your database values to contain html code in them?  Like will someone's last name have something other than a legitimate name value in it? Or a phone number? or a contract type?  Those values should have been validate before being saved so as to guarantee that they were valid values.  A contract type should have been checked against a lookup table that contains all of the valid types so that you know that your database is accurate.  I really don't see how any of your table elements would have any html code in them if you did all of the checking during the save process. 

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.