What are you trying to do?
Shouldn’t you add:
$baboon = getstockstats(‘aapl’);
echo $baboon;
?
Andrew Nevins
(@anevins)
WCLDN 2018 Contributor | Volunteer support
What isn’t working, in which line?
What, if any, are the errors shown?
whats the difference between echo and return ?
All I wanted to do was print “yourname is some guy”
I changed to this,
function getstockstats($stocksymbol)
{
if ( $stocksymbol == "aapl" ) {
$result = "Test!<br />";
}
echo $result;
}
and it worked. But shouldnt returning $result also print it out?
One last question,
function widget($args, $instance)
{
function getstockstats($stocksymbol)
{
include_once('class.yahoostock.php');
$objYahooStock = new YahooStock;
$objYahooStock->addFormat("snl1d1t1cvc1p2");
$objYahooStock->addStock("msft");
foreach( $objYahooStock->getQuotes() as $code => $stock)
{
?>
Code: <?php echo $stock[0]; ?> <br />
Name: <?php echo $stock[1]; ?> <br />
Last Trade Price: <?php echo $stock[2]; ?> <br />
Last Trade Date: <?php echo $stock[3]; ?> <br />
Last Trade Time: <?php echo $stock[4]; ?> <br />
Change and Percent Change: <?php echo $stock[5]; ?> <br />
Volume: <?php echo $stock[6]; ?> <br /><br />
<?php
}
if ( $stocksymbol == "aapl" ) {
$result = "Test!<br />";
echo $result;
}
}
getstockstats("aapl");
echo $after_widget;
}
Why doesn’t my function work when I add the echos inside that foreach loop? I have a feeling it is some sort of permissions issue but am not sure
UGH.
The directory starts in the plugin root and NOT the directory that the file is located in.
I changed
include_once(‘class.yahoostock.php’);
to
include_once(‘prediction-widget/class.yahoostock.php’);
and now it works. ARGH
One more issue
$objYahooStock->addStock(“$stocksymbol”);
That line is getting read as $stocksymbol
What do I have to do change in order to make it read the variable, as opposed to $stocksymbol?
I’ve tried wrapping in braces like
$objYahooStock->addStock(“{$stocksymbol}”);
but it did not work
Solved!
I removed the quotes.
$objYahooStock->addStock($stocksymbol);
Thank you everybody for so much help 🙂