• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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.
 
Once upon a time there were three bears. And they were visted by a golden haired tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic