tazeha Posted July 19, 2015 Share Posted July 19, 2015 Hello when I run my code give error Undefined offset: -1 in 3 line : if($pays[$i]['Amount'] < $pays[($i-1)]['Amount']) elseif($pays[$i]['Amount'] > $pays[($i-1)]['Amount']) .$pays[$i]['price']. <?php $params =null; //or any params $mrkfPDO = new PDO('mysql:host=localhost;dbname=YOUR_DB_NAME', 'DB_USER', 'DB_PASS', array( PDO::ATTR_PERSISTENT => true, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8" ) ); $mrkfStatement = $mrkfPDO->prepare("SELECT Date, Amount FROM payments limit 0,100"); $mrkfStatement->execute($params); $pays = $mrkfStatement->fetchAll(PDO::FETCH_ASSOC); for($i=0; $i<=count($pays); $i++) { $color = 'black'; if($pays[$i]['Amount'] < $pays[($i-1)]['Amount']) $color="red"; elseif($pays[$i]['Amount'] > $pays[($i-1)]['Amount']) $color = 'green'; else $color = 'black'; echo "<tr> <td>" . $pays[$i]['Date'] . "</td> <td> <span style='color: $color'>" .$pays[$i]['Amount']. "</span> </td> </tr>"; } ?> Link to comment Share on other sites More sharing options...
tazeha Posted July 19, 2015 Author Share Posted July 19, 2015 My problem fix.. I should use $i=1 instead $i=0 because --- ['Amount'] < $pays[($i-1) 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