Jump to content

run function from class on mysql array results


will35010
Go to solution Solved by will35010,

Recommended Posts

Hello,

 

I think I've been staring at this too long and now cannot see it straight anymore so another pair of eyes would be greatly appreciated.

 

I have the below code that pulls a result from mysql and puts it into an array. I now need to run a function from my class on one of the items in the array since I am using smarty to template and cannot call the function from the template or shouldn't anyway.

<?php

ini_set('display_errors', 1);
error_reporting(E_ALL);

include ('classes/TrackingBoardClass.php');
include ('functions.inc.php');

$clientID = "1";


$TrackingClass = new TrackingBoardClass();
$results = $TrackingClass->GetBoardResults($clientID);
if ($results != "") {
    while ($row2 = mysqli_fetch_assoc($results)) {

        $boardresults[] = $row2['priorityID'];
    }
}

//print_r($boardresults);

foreach ($boardresults as $value) {
    echo $TrackingClass->GetPriority($clientID, $value)."<br>";
}

?>

The $TrackingClass->GetPriority is the function that I am trying to run on the results, but I get error: Object of class mysqli_result could not be converted to string.

 

Any help or insights would be greatly appreciated. Thank you!

Link to comment
Share on other sites

the only thing that is apparent from the code you posted is that your $TrackingClass->GetPriority() method likely (only you know for sure) returns a mysqli result object and you are trying to echo that.

 

wouldn't you need to to fetch a row from that result set, then access a specific element of that row before you could echo its value? or even better, wouldn't a method named GetPriority() do all the necessary work internally and just return the priority value?

Link to comment
Share on other sites

  • Solution

the only thing that is apparent from the code you posted is that your $TrackingClass->GetPriority() method likely (only you know for sure) returns a mysqli result object and you are trying to echo that.

 

wouldn't you need to to fetch a row from that result set, then access a specific element of that row before you could echo its value? or even better, wouldn't a method named GetPriority() do all the necessary work internally and just return the priority value?

 

Thank you for pointing me in the right direction. It was the way the function was returning the result. Thank you again!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.