0

I am executing below query in mysql but its not working. Giving following error,

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /usr/share/info/.info/php/userutil.php on line 228

This is my code:

  echo $con = mysql_connect('localhost', 'root', 'root123','qhutm');
  if(!$con){
    echo 'connection failed';
   }else{

    echo 'conn successful';
  }
    $query ="SELECT no_of_license 
             FROM Service_Master AS s,Service_Details AS d
             WHERE s.service_id=d.service_id 
             AND s.description='Internet Access' ";
    $result = mysql_query($query,$con)
    print_r($result);
    echo $result.'--pra';
    echo mysql_num_rows($result);        

output

conn successful

If I echo and execute same query on mysql it works fine.
If I echo $con it gives Resource id #126

Jenz
  • 8,172
  • 7
  • 41
  • 75

5 Answers5

1

Maybe if you use a normal join?

select no_of_license 
from   Service_Master as s
join   Service_Details as d on s.service_id = d.service_id 
where  s.description = 'Internet Access'
winkbrace
  • 2,634
  • 24
  • 19
0

Try with JOIN like

"SELECT no_of_license 
         FROM Service_Master AS s,
         LEFT JOIN Service_Details AS d
         ON s.service_id=d.service_id 
         WHERE s.description='Internet Access'
Gautam3164
  • 28,027
  • 10
  • 58
  • 83
0
$query ="SELECT XXXXX FROM `Service_Master` s, `Service_Details` d WHERE s.service_id=d.service_id  AND s.description='Internet Access' ";   


replace it 
and also XXXXX  if no_of_license field in Service_Master this table write  s.`no_of_license`
else if this field  is in Service_Details than write d.`no_of_license`
i think its work fine
wild
  • 355
  • 1
  • 3
  • 14
0

you have not selected the database, use mysql_select_db()

your connection should be like this

<?php

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Not connected : ' . mysql_error());
}

$db_selected = mysql_select_db('foo', $link);
if (!$db_selected) {
    die ('Can\'t use foo : ' . mysql_error());
}
?>
PravinS
  • 2,642
  • 3
  • 20
  • 25
0

You forgot to select db after creating db connection.
Please add below line after creating connection with database.

mysql_select_db('qhutm', $con);

Praveen D
  • 2,313
  • 2
  • 27
  • 43