0

I'm using this PDO query to fetch all the data I need from Value and dateid:

$pdo = new PDO('mysql:host=localhost;dbname=contisec_portal', 'root', '');
        $date = date("o-m-d");
        $stmt = $pdo->query("SELECT stock_names.Value,stock_names.Fileid,date_header.dateid FROM stock_names,date_header WHERE SEDOL = '$stocksel' AND date_header.fileid = stock_names.FileID");

Does anybody know how I can sort the two columns into their own arrays (i.e. $valuearray and $dateidarray)?

Many Thanks,

Ed

2
Contributors
6
Replies
24
Views
4 Years
Discussion Span
Last Post by ebutt13
0

Maybe:

$stmt = $pdo->query("SELECT stock_names.Value,stock_names.Fileid,date_header.dateid FROM stock_names,date_header WHERE SEDOL = '$stocksel' AND date_header.fileid = stock_names.FileID");

$values = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
$dates = $stmt->fetchAll(PDO::FETCH_COLUMN, 2);

Top of head, not tested.

0

Do you know how I can print out all the values so I can test to see the array is being filled?

0
print_r($values);

As these questions are pretty rudimentary, how about looking at some tutorials or the php.net manual?

0

Ok, I've tested it out and it works with the first array ($values) but nothing displays for dates.
Any ideas?

Thanks,

Ed

0

Sorry, my mistake - the first fetchAll has come to the end of the records so there's nothing left to fetch. Noob mistake! Why not use a simple while loop?

$values = array();
$dates = array();
while($data = $stmt->fetch(PDO::FETCH_ASSOC)) {
  $values[] = $data['value'];
  $dates[] = $data['date'];
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.