• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

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
  • 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
  • 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
  • Quote
  • Report post to moderator
Thank You , I get it.
 
I brought this back from the farm where they grow the tiny ads:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic