Jump to content

Recommended Posts

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 advance
A.
Link to comment
https://forums.phpfreaks.com/topic/3480-mysql-and-php-array/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/3480-mysql-and-php-array/#findComment-11975
Share on other sites

[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]
Link to comment
https://forums.phpfreaks.com/topic/3480-mysql-and-php-array/#findComment-12007
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.