Image Showing, but not the right one !
Hi... Again :)
Just after i fixed my previous problem thanks to me failing to put an echo before ".."
I worked out that the incorrect image was showing. I'm making a stock trading website, and there will be an red arrow pointing downwards when it detects at - (negative sign). If it doesn't detect it, then it displays the green up arrow.
Problem is, it is showing the green arrow for negative values, and the green arrow for positive values....
Here's the code :
<?php if($_SESSION['loggedin'] === "true") { ?>
<?php include("includes/getstock.php"); ?>
<br/>
<?php $stockdata = GetStockInfo("GOOG"); ?>
Stock Name : <?php echo $stockdata['name']; ?><br/>
Stock Price : <?php echo $stockdata['price']; ?><br/>
Stock Difference :
<?php if(strpos($stockdata['diff'], "-")) { echo "<img src=\"images/down.png\" />"; } else { echo "<img src=\"images/up.png\" /> "; } ?>
<?php echo $stockdata['diff']; ?><br/><br/>
<?php $stockdata = GetStockInfo("AAPL"); ?>
Stock Name : <?php echo $stockdata['name']; ?><br/>
Stock Price : <?php echo $stockdata['price']; ?><br/>
Stock Difference :
<?php if(strpos($stockdata['diff'], "-")) { echo "<img src=\"images/down.png\" />"; } else { echo "<img src=\"images/up.png\" /> "; } ?>
<?php echo $stockdata['diff']; ?>
<?php } ?>
I'm "trying" to use strpos to find the negative sign, but somehow it isn't working out.
Any help would be greatly appreciated ;)
cuonic
Junior Poster in Training
56 posts since Mar 2011
Reputation Points: 16
Solved Threads: 9
I'd do it slightly differently.
Get the difference and see if it is < 0. If so, it's negative. I'd wouldn't use image tags either, just add a class to the 'Stock Difference :' tag (which you don't seem to have). This class could then be referenced in a css file. You should enclose your labels within some sort of tags, e.g. li or p.
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
$class = ($stockdata['diff'] < 0) ? 'neg' : 'pos';
....
<p class="<?php echo $class;?>">Stock Difference : <?php echo $stockdata['diff']; ?></p>
Then apply some CSS to .pos and .neg, e.g. a background image and coloured text.
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
cuonic
Junior Poster in Training
56 posts since Mar 2011
Reputation Points: 16
Solved Threads: 9