Rahul Kumar
Rahul Kumar

Reputation: 1

how to combine three tables in one query an i need all the rows?

//( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given

No idea getting this problem. Please guys help me out. Here is my code:

$query = "SELECT t1.employeecode, t1.employeename, t2.v, t2.w, t3.total, t3.totals
                FROM invoice t1,salaries t2,table1 t3
                WHERE t1.employeecode = salaries.employeecode AND
                t1.employeecode = t3.employeecode
                ORDER BY t1.employeecode ASC";

    $result = mysql_query($query,$con);

    if(mysql_num_rows($result)>0){

        echo '<table><tr><th>Article title</th>&nbsp;</tr>';
        while($row=mysql_fetch_array($result)){
            //$postedon = strftime("%A %e %b %Y",strtotime($row['postedon']));
            echo '<h1><tr><td><a href="3.php?employeecode='.$row["employeecode"].'">'.$row["deparment"].'</a></td></tr></h1>';
        }

Upvotes: 0

Views: 115

Answers (4)

Rikesh
Rikesh

Reputation: 26451

$result is boolean (false) cause there must be problem with your query. Help yourself by getting error in your query using mysql_error(),

$result = mysql_query($query,$con) or die(mysql_error()); 

Note: Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated.

So use either PDO or MySQLi (IMO PDO is way to go)

Upvotes: 2

ksugiarto
ksugiarto

Reputation: 951

Try changing your salaries to be t2..

WHERE t1.employeecode = salaries.employeecode AND

like

WHERE t1.employeecode = t2.employeecode AND

I don't know, but what I know when we done give some alias to a table, our dbms would read that alias, not that native table name.

Upvotes: 0

Ripa Saha
Ripa Saha

Reputation: 2540

Since you aliased your salaries table to t2 you have to reference it as t2 in your where clause:

$query = "SELECT t1.employeecode, t1.employeename, t2.v, t2.w, t3.total,
            t3.totals
            FROM invoice t1,salaries t2,table1 t3
            WHERE t1.employeecode = t2.employeecode AND
            t2.employeecode = t3.employeecode
            ORDER BY t1.employeecode ASC";

Upvotes: 2

SeeSharp
SeeSharp

Reputation: 179

it seems your query is not working and fails returning FALSE bool value. To check the reason you need to check your query after dynamically building at run time follow below steps

$result = mysql_query($query) or die($query."

".mysql_error());

check the error message. seems some wrong column must be included

Upvotes: 0

Related Questions