Jump to content

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

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.