Elli Joshua Rey
Elli Joshua Rey

Reputation: 45

SQL error Catchable fatal error: Object of class stdClass could not be converted to string

function getjobid() {
global $geotag_table, $wpdb;
$qry = "SELECT * FROM mirdc_jo_form WHERE  jo_id = (SELECT MAX(jo_id)  FROM mirdc_jo_form)";
$desc = $wpdb->get_results($qry);

return $desc; }

can you help me guys.. i am trying to get the id from my table and try to show the data to my wordpress..

<?php  foreach (getjobid() as $generatedid) {
echo $generatedid;?>  #<------ this is the error                       

this is my wordpress code.. can you teach me how i convert the object to string.. to show the result to my wordpress.

Upvotes: 1

Views: 243

Answers (2)

Manish Jesani
Manish Jesani

Reputation: 1347

Please try this is batter for your code

function getjobid() {
global $geotag_table, $wpdb;
$qry = "SELECT jo_id FROM mirdc_jo_form WHERE  jo_id = (SELECT MAX(jo_id)  FROM mirdc_jo_form)";
$desc = $wpdb->get_col($qry);

return $desc[0]; }
$lastid = getjobid();

Upvotes: 2

Ashwini Agarwal
Ashwini Agarwal

Reputation: 4858

$generatedid is an Object and containing entire row of data. You need to specify what column you want from that row.

You should try var_dump($generatedid) to view all the data.

foreach (getjobid() as $generatedid) {
    echo $generatedid->jo_id; // or whatever ID you want from DB 
}

Upvotes: 1

Related Questions