tazeha Posted July 21, 2015 Share Posted July 21, 2015 (edited) Hello with curl every 1 min go to the web and get the coin price and then store in the database. Now in my code compare latest tow records from table db ... if new price higher of old price echo price with color green.. and if less echo with red color and if equal echo with black color. <table border="1" width="50%"> <tr> <td>Date</td> <td>Amont</td> </tr> <?php $params =null; //or any params $mrkfPDO = new PDO('mysql:host=localhost;dbname=usd', 'root', '', array( PDO::ATTR_PERSISTENT => true, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8" ) ); $mrkfStatement = $mrkfPDO->prepare("select * from uds order by id desc limit 2 ");$mrkfStatement->execute($params);$pays = $mrkfStatement->fetchAll(PDO::FETCH_ASSOC);$color = 'black';$resultcount = count($pays);if ($resultcount == 2) { if ($pays[1]['price'] > $pays[0]['price']) $colour = 'red'; if ($pays[1]['price'] < $pays[0]['price']) $colour = 'green'; }if ($resultcount > 0) { echo "<tr><td><span style='color: $color'>" .$pays [$resultcount-1]['price'] . "</span></td></tr>"; } ?> But I don't know why when echo higher price dos not change color to green.. and always is black Edited July 21, 2015 by tazeha Link to comment Share on other sites More sharing options...
Ingolme Posted July 21, 2015 Share Posted July 21, 2015 In one place you're using the variable $colour and in another you're using the variable $color Link to comment Share on other sites More sharing options...
tazeha Posted July 21, 2015 Author Share Posted July 21, 2015 I fixed but until not working Link to comment Share on other sites More sharing options...
Ingolme Posted July 21, 2015 Share Posted July 21, 2015 There should not be a space between the variable and square brackets in this code fragment: $pays [$resultcount-1]['price'] Have you checked the value of $color to see what is in it? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now