derrick24 Posted November 6, 2008 Share Posted November 6, 2008 Hi, is it possible to create an extra field during a select query and set the values of that field. ie: fakeField does not exist in the database, but I need it to be part of the returned array for manipulation in php SELECT table.*, table.fakeField=10 FROM table thanks Link to comment https://forums.phpfreaks.com/topic/131625-solved-is-it-possible-to-create-an-extra-field-during-a-select-query/ Share on other sites More sharing options...
derrick24 Posted November 6, 2008 Author Share Posted November 6, 2008 IF I could do the as posted above, I would not have to write something like below. if(count($newArray) > 0) { // Combine products with number or orders foreach($newArray as $key => $value) { foreach($array as $subKey => $subValue) { if ($newArray[$key]['id'] == $subKey) { $newArray[$key]['amount'] = $subValue; } } } return $newArray; } Link to comment https://forums.phpfreaks.com/topic/131625-solved-is-it-possible-to-create-an-extra-field-during-a-select-query/#findComment-683662 Share on other sites More sharing options...
fenway Posted November 6, 2008 Share Posted November 6, 2008 Hi, is it possible to create an extra field during a select query and set the values of that field. ie: fakeField does not exist in the database, but I need it to be part of the returned array for manipulation in php SELECT table.*, table.fakeField=10 FROM table thanks Sure... use this: SELECT table.*, '10' as fakeField FROM table Link to comment https://forums.phpfreaks.com/topic/131625-solved-is-it-possible-to-create-an-extra-field-during-a-select-query/#findComment-683722 Share on other sites More sharing options...
derrick24 Posted November 7, 2008 Author Share Posted November 7, 2008 Awesome, thanks Link to comment https://forums.phpfreaks.com/topic/131625-solved-is-it-possible-to-create-an-extra-field-during-a-select-query/#findComment-684389 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.