0
//( ! ) 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>';
        }
Rikesh
  • 26,156
  • 14
  • 79
  • 87
  • 1
    Check the error with `mysql_query($con)` – pyrospade Feb 20 '13 at 05:34
  • 3
    Welcome to Stack Overflow! Please, don't use `mysql_*` functions to write new code. They are no longer maintained and the community has begun [deprecation process](http://goo.gl/q0gwD). See the [red box](http://goo.gl/OWwr2)? Instead you should learn about [prepared statements](http://goo.gl/orrj0) and use either [PDO](http://goo.gl/TD3xh) or [MySQLi](http://php.net/mysqli). If you can't decide which, [this article](http://goo.gl/YXyWL) will help you. If you pick PDO, [here is good tutorial](http://goo.gl/b2ATO). Also see [Why shouldn't I use mysql functions in PHP?](http://goo.gl/J5jAo) – Daedalus Feb 20 '13 at 05:34
  • Your `mysql_query()` fails and returns `FALSE`. Make sure your `SELECT` works in mysql or any other IDE (e.g. phpmyadmin) you're using – peterm Feb 20 '13 at 05:37
  • what is the structure of your tables please provide foreign_keys and use joins – Muhammad Raheel Feb 20 '13 at 05:41

4 Answers4

2

$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)

Zoe
  • 27,060
  • 21
  • 118
  • 148
Rikesh
  • 26,156
  • 14
  • 79
  • 87
  • I got the result. But in that i ve created a 2 different profiles for each person. but i'm getting a same profile details for both the person. eg: sam & john are having different profile details. But when i open sam's profile detail it's showing john's profile detail. Actually its showing a single details in every different profile. Help me guys. – Rahul Kumar Feb 20 '13 at 07:25
2

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";
vstm
  • 12,407
  • 1
  • 51
  • 47
Ripa Saha
  • 2,532
  • 6
  • 27
  • 51
  • I got the result. But in that i ve created a 2 different profiles for each person. but i'm getting a same profile details for both the person. eg: sam & john are having different profile details. But when i open sam's profile detail it's showing john's profile detail. Actually its showing a single details in every different profile. Help me. – Rahul Kumar Feb 20 '13 at 07:47
  • @RahulKumar the employeecode will be different for 2 profile. check employeecode. May be it's same for 2 profiles you are passing. – Ripa Saha Feb 20 '13 at 07:50
  • @ripa the employeecode is different only in both the profile. actually i ve given "PRIMARY KEY" to employeecode.. – Rahul Kumar Feb 20 '13 at 08:02
  • @RahulKumar fine. so check your url link for 2 profiles. if possible share it. – Ripa Saha Feb 20 '13 at 08:04
  • http://localhost/newform1/3.php?employeecode=45678 http://localhost/newform1/3.php?employeecode=323223 – Rahul Kumar Feb 20 '13 at 08:21
  • now check your code from where you are picking up your result. check whether it's picking up with exact employeecode. and also check your DB. changed field. – Ripa Saha Feb 20 '13 at 08:25
  • "Here is my query" if(isset($_GET["employeecode"])){ $employeecode=$_GET["employeecode"]; require_once("dbconfig.php"); $query = ("select t1.employeecode,t1.employeename,t1.designation t2.v,t2.w,t2.x,t2.a,t2.b, t3.total, t3.totals,t3.totalss,t3.netsalary,t3.amount FROM invoice t1,salaries t2,total1 t3 WHERE t1.employeecode = t2.employeecode AND t2.employeecode = t3.employeecode ORDER by t1.employeecode ASC"); $result = mysql_query($query,$con); if(mysql_num_rows($result)>0){ $row = mysql_fetch_array($result); – Rahul Kumar Feb 20 '13 at 10:51
0

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

SeeSharp
  • 179
  • 1
  • 4
  • 12
0

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.

ksugiarto
  • 940
  • 1
  • 17
  • 40