analyst Posted February 19, 2006 Share Posted February 19, 2006 Hello to everybody, I'm new.I've this problem.I Have a MySQL DB with a table with financial data.The table has five columns: DATE, OPEN, HIGH, LOW, CLOSE and thousand of rows.To plot the data on a chart I need to get only last 50 rows of the table and put each column data in a single array.Could you help me with a PHP code ?Thanks in advanceA. Quote Link to comment Share on other sites More sharing options...
fenway Posted February 19, 2006 Share Posted February 19, 2006 Well, you can use a "LIMIT 50" clause to get only 50 rows, but you'll need to have an ORDER BY clause, probably by date descending, to get the most "recent" 50. As far as the array goes, simply create 5 empty arrays, and push onto each one as you iterate through the result set. Quote Link to comment Share on other sites More sharing options...
wickning1 Posted February 20, 2006 Share Posted February 20, 2006 [code]<?php// open a mysql database connection$result = mysql_query("SELECT * FROM myTable ORDER BY DATE DESC LIMIT 50", $dblink);while ($row = mysql_fetch_array($result)) { $date[] = $row['date']; $open[] = $row['open']; $high[] = $row['high']; $low[] = $row['low']; $close[] = $row['close'];}mysql_free_result($result);?>[/code] Quote Link to comment Share on other sites More sharing options...
fenway Posted February 20, 2006 Share Posted February 20, 2006 That's what I'm talking about! BTW, I was under the impression that you needed to declare the arrays first -- but apparently not. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.