• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Object of class mysqli_result could not be converted to string/int

 
Ranch Hand
Posts: 391
1
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my table ,i have a field called base_pay with type int(11).

When i retrieve the base_pay of a employee and try to add or multiply the base_pay.
Here are my queries


$result = mysqli_query($con,"SELECT base_pay FROM guest where name='Mahtab'");
mysqli_query($con,"UPDATE guest SET net_pay='$result*15"
WHERE name='Mahtab'");

It says Catchable fatal error: Object of class mysqli_result could not be converted to string

Does it mean that the return type of query is not int.

If not then how to do some mathematics on an int field retrieved from table.

 
Ranch Hand
Posts: 71
PHP Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is correct, a mysql_result cannot be converted into an integer; instead a mysql_result is a handle for a collection of data that you have to get a row at a time. So what you need to do is extract the integer from the mysql_result, like this:

$row = mysql_fetch_row($result);
$base_pay = $row[0];

There are other ways to do this also. Try looking up a PHP with MySQL turorial.
 
Mahtab Alam
Ranch Hand
Posts: 391
1
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You , I get it.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic