Jump to content

php object help


kansasakki

Recommended Posts

hello all,

 

I am new to php, and getting better using the object oriented approach.  I have been a procedural programmer for several years, with a limited exposure to OOP. 

 

I have a question about pulling two values from an object.

 

the following code is an excerpt from a class form.

 


      function getstocklist($currentcount){   
         $transactions = $currentcount['count'];
         $current = mysql_query("SELECT * FROM current_positions WHERE positiontype = 'long' OR positiontype = 'short'");
         $tickers = '';
         while ($stock = mysql_fetch_array($current)){
         $tickers .= $stock['positionticker'] . ',';
            
            $stockList[] = array(
               'shares' => round(($stock['positioncost']/$stock['positionprice']),0),
               'date' => date("m/d/Y G:i:s", $stock['positiontime']-(45*60)),
               'ticker' => $stock['positionticker'],
               'type' => $stock['positiontype'],
               'price' => $stock['positionprice'],
            );
         }
         return($tickers);
      }

 

I would like to get both the value of $tickers and the array $stockList.  I am not sure how to proceed.

 

any suggestions would be greatly appreciated.

 

Thanks

Kansas

Link to comment
https://forums.phpfreaks.com/topic/233662-php-object-help/
Share on other sites

I'm not sure what this has to do with Oop vs. procedural.  The mechanics of "return" are the same.  You can return a single variable, however that is not a limitation, as the variable can be any of the php types, including objects themselves.  The simple answer here would be to return an array with both the items you need in it.

 

return array('tickers' => $tickers, 'stocklist' => $stockList);

Link to comment
https://forums.phpfreaks.com/topic/233662-php-object-help/#findComment-1201384
Share on other sites

... The mechanics of "return" are the same.  You can return a single variable, however that is not a limitation, as the variable can be any of the php types, including objects themselves. The simple answer here would be to return an array with both the items you need in it.

 

 

This was a lesson in itself. 

Link to comment
https://forums.phpfreaks.com/topic/233662-php-object-help/#findComment-1201392
Share on other sites

I would highly suggest reading this tutorial. You may learn something, even though I had to take a class to completely understand the point of a class.

 

 

http://www.phpfreaks.com/tutorial/oo-php-part-1-oop-in-full-effect

 

Thank your for the tutorial, I have read it over and bookmarked the link!

 

Kansas

Link to comment
https://forums.phpfreaks.com/topic/233662-php-object-help/#findComment-1201466
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.