I Select * From my sql table in PHP, and I convert it to JSON, so the results are like this:
([
{"id":"350","Name":"BlaBla","Info":"BlaBla"},
{"id":"351","Name":"BlaBla","Info":"BlaBla"},
{"id":"352","Name":"BlaBla","Info":"BlaBla"}
]);
I scrape a clients website for images (this is a request of the client) based on the id in the records above, and I output images into a similar array/dictionary and output into JSON:
([
{"image1":"http://Sourceofimg.jpg"},
{"image2":"http://Sourceofimg.jpg"},
{"image3":"http://Sourceofimg.jpg"},
{"image4":"http://Sourceofimg.jpg"},
{"image5":"http://Sourceofimg.jpg"}
]);
So lets say I scrape a page, page.php?id=350, I'd get a similar output to the image array above, how can I append/add that result to the first array where id=350?
EDIT
This is where I would like to combine the arrays:
while ($row = mysql_fetch_assoc($results))
{
$rows[] = $row;
$url = 'http://www.url.com/page.php?id='.$row['id'].'';
$html = file_get_html($url);
foreach($html->find('div.classvalue') as $element){
foreach($element->find('img') as $img){
$images[] = array("image".$i."" => $img->src);
$i = $i + 1;
$rows = array_merge($rows, $images);
} } }
My version clearly does not work, it seems to be appending new images to the already existing image[] therefore the last element of $rows[] will get the full list of images, where I just want the images tied in with that id. Also by merging, it does not merge correctly I get an output like this e.g:
([
{"id":"350","Name":"BlaBla","Info":"BlaBla"},
{"image1":"http://Sourceofimg.jpg"},
{"image2":"http://Sourceofimg.jpg"},
{"id":"351","Name":"BlaBla","Info":"BlaBla"}
]);
I would like it like:
([
{"id":"350","Name":"BlaBla","Info":"BlaBla", "image1":"http://Sourceofimg.jpg", "image2":"http://Sourceofimg.jpg"} etc...
]);
}for the first for loop?}missing. Please check your code because you really need to close a for loop after you've opened it...