This question is probably easy to solve, but here it comes.
I would like to get the latest data from each vendor (the latest row inserted into the database for each vendor).
This is some sample data from MySQL:
id vendorId vendor url delay price0 price1 price2 price3 price4 price5 price6 date 1 1 vendor1 vendor1.com 0 12 15 18 14 25 28 25 2012-01-18 09:43:40 2 2 vendor2 vendor2.com 0 12 15 18 14 25 28 25 2012-01-18 09:43:40 3 1 vendor1 vendor1.com 0 15 17 122 12 30 52 53 2012-01-18 10:02:40 4 2 vendor2 vendor2.com 0 13 12 123 16 54 61 91 2012-01-18 10:02:40
I would like the output to be:
id vendorId vendor url delay price0 price1 price2 price3 price4 price5 price6 date 3 1 vendor1 vendor1.com 0 15 17 122 12 30 52 53 2012-01-18 10:02:40 4 2 vendor2 vendor2.com 0 13 12 123 16 54 61 91 2012-01-18 10:02:40
What would the SQL be and how would I put the values into this array?
$vendor = array(
array('vendorId' => '1', 'vendor' => 'vendor1', 'url' => 'vendor1', 'delay' => 0, 'price0' => 12, 'price1' => 15, 'price2' => 26, 'price3' => 14, 'price4' => 25, 'price5' => 64, 'price6' => 512),
array('vendorId' => '2', 'vendor' => 'vendor2', 'url' => 'vendor2', 'delay' => 0, 'price0' => 12, 'price1' => 15, 'price2' => 26, 'price3' => 14, 'price4' => 25, 'price5' => 64, 'price6' => 512)
);
Thanks in advance
Also, I forgot to mention: There will be more than just 2 vendors in the database, so I’d prefer that they’d be picked up per auto.
You updated your question with how you should obtain the resultset into an array.
Refer here: http://php.net/manual/en/function.mysql-fetch-array.php
You will then be able to add each row as an associative array to another array containing all your vendors, accessible by key/value.