MySQL Forums
Forum List  »  PHP

adding fields based on results
Posted by: ade harris
Date: September 19, 2012 05:15AM

i have a query that returns details but i want to be able to add the image url based on the id's that are returned (the results are being fed into a json array) ie

i get this
[0] => stdClass Object
(
[description] => Rocks 2011
[id] => 1730
[parent_id] => 1
[album_cover_item_id] => 11916
)

album_cover_item_id is the same as the id of the photo thats being used as the cover

so what i need is the row for id=11916 added to the query i thought this would work

$result = mysql_query("
SELECT
description,
id,
parent_id,
album_cover_item_id,
relative_path_cache
FROM items
WHERE description LIKE '%rocks%'

UNION ALL

SELECT
id,
description,
parent_id,
album_cover_item_id,
relative_path_cache
FROM items
WHERE id = album_cover_item_id
ORDER BY id DESC
".$limit_sql,

$connection
) or die("error querying database1");

this is the layout

id | album_cover_id | description | relative_path_cache
1 148 rocks 2012 null
2 256 rocks 2011 null
.....
148 null null rocks2012.jpg
256 null null rocks2011.jpg

so basically my simple output would be on a search in description for LIKE "%rocks%" would be

rocks 2012, rocks2012.jpg
rocks 2011, rocks2011.jpg

if this makes sense ? :)

Options: ReplyQuote


Subject
Written By
Posted
adding fields based on results
September 19, 2012 05:15AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.