I am getting the result below. i want to print the question and cat_id but don't know how??? Actually i'm new in codeigniter. Any help will be appreciated .
Array
(
[data] => Array
(
[0] => Array
(
[records] => Array
(
[0] => stdClass Object
(
[qst_id] => 1
[question] => Describe a major change that occurred in a job that you held. How did you adapt to this change?
[cat_id] => 1
)
[1] => stdClass Object
(
[qst_id] => 2
[question] => Tell about a situation in which you had to adjust to changes over which you had no control. How did you handle it?
[cat_id] => 1
)
)
[cat_id] => 1
)
[1] => Array
(
[records] => Array
(
)
[cat_id] => 4
)
[2] => Array
(
[records] => Array
(
[0] => stdClass Object
(
[qst_id] => 3
[question] => Give an example of a situation where others were intense but you were able to maintain your composure.
[cat_id] => 6
)
)
[cat_id] => 6
)
)
)
Related
I displayed the data from database using the following code
$mani = DB::select('select id from employee');
Output :
Array (
[0] => stdClass Object (
[id] => 1
)
[1] => stdClass Object (
[id] => 2
)
[2] => stdClass Object (
[id] => 3
)
[3] => stdClass Object (
[id] => 4
)
)
I need the following Exact output :
Array (
[0] => 1
[1] => 2
[2] => 3
[3] => 4
)
Please share the solution. Thank you
Change your code to use pluck() instead, so change
$mani = DB::select('select id from employee');
to
$mani = DB::table('employee')->pluck('id');
If you are using laravel-5.2, then change
$mani = DB::table('employee')->lists('id');
But if you are using laravel 5.2 and greater version
$mani = DB::table('employee')->plunk('id');
My whole moto in this question is to make a new array from existing array and to reverse the first and second index of array.
I have an array
Array
(
[0] => Array
(
[0] => Array
(
[field] => Array
(
[name] => name
[tabindex] => 0
)
[colspan] => 3
)
)
[1] => Array
(
[0] => Array
(
[field] => Array
(
[name] => sequence
[tabindex] => 0
)
[colspan] => 3
)
)
[2] => Array
(
[0] => Array
(
[field] => Array
(
[name] => description
[tabindex] => 0
)
[colspan] => 3
)
)
[3] => Array
(
[0] => Array
(
[field] => Array
(
[name] => status
[tabindex] => 0
)
[colspan] => 3
)
)
[4] => Array
(
[0] => Array
(
[field] => Array
(
[name] => modified_by_name
[customCode] => {$fields.date_modified.value} {$APP.LBL_BY} {$fields.modified_by_name.value}
[label] => LBL_DATE_MODIFIED
[tabindex] => 0
)
[colspan] => 3
)
)
[5] => Array
(
[0] => Array
(
[field] => Array
(
[name] => created_by_name
[customCode] => {$fields.date_entered.value} {$APP.LBL_BY} {$fields.created_by_name.value}
[label] => LBL_DATE_ENTERED
[tabindex] => 0
)
[colspan] => 3
)
)
[6] => Array
(
[0] => Array
(
[field] => Array
(
[name] =>
)
)
[1] => Array
(
[field] => Array
(
[name] =>
)
)
)
)
Now i have to make a new array with first index on second and second on first index like this But have to do only in smarty not in php etc
Array
(
[0] => Array
(
[0] => Array
(
[field] => Array
(
[name] => name
[tabindex] => 0
)
[colspan] => 3
)
[1] => Array
(
[field] => Array
(
[name] => sequence
[tabindex] => 0
)
[colspan] => 3
)
[2] => Array
(
[field] => Array
(
[name] => description
[tabindex] => 0
)
[colspan] => 3
)
[3] => Array
(
[field] => Array
(
[name] => status
[tabindex] => 0
)
[colspan] => 3
)
[4] => Array
(
[field] => Array
(
[name] => modified_by_name
[customCode] => {$fields.date_modified.value} {$APP.LBL_BY} {$fields.modified_by_name.value}
[label] => LBL_DATE_MODIFIED
[tabindex] => 0
)
[colspan] => 3
)
[5] => Array
(
[field] => Array
(
[name] => created_by_name
[customCode] => {$fields.date_entered.value} {$APP.LBL_BY} {$fields.created_by_name.value}
[label] => LBL_DATE_ENTERED
[tabindex] => 0
)
[colspan] => 3
)
)
)
I think the following might help you.
You could loop the array you have and fill a new array with the values. Lets call the original $firstArray and the new one $newArray. I see that the first item from the subarrays are what you need(and there are no other items apart from 0) so you could do the following:
{$newArray = []}
{foreach $firstArray as $item}
{$newArray[] = $item.0}
{/foreach}
$item.0 selects the first subarray(there are no other). You might have to use $item[0] depending on your smarty version.
If there is more than 1 subarray, then loop $items first before you add an array to the $newArray.
It looks as if there's another array encapsuling your firstArray, so perhaps you need to select the subarray from the main one first....
note: I used smarty 3. Perhaps you use a different version, be sure to check the syntax for your version.
Array
(
[0] => stdClass Object
(
[id] => 16
[department_id] => 4
[employee_status] => 1
)
[1] => stdClass Object
(
[id] => 17
[department_id] => 8
[employee_status] => 1
)
)
i found a solution that sort object array
function cmp($a, $b) {
return $b->department_id - $a->department_id;
}
$sirtedArray=usort($employeelist, "cmp");
I have implemented a multi-level comment system where comments and their replies are pulled out of a SQL database and stored (via a PHP routine) in an array. Here is an example of the data structure of a comment which has 2 nested replies (main comment -> [child] reply -> [child] reply to reply):
Array ( [0] => stdClass Object ( **[self]** => stdClass Object ( [id] => 1 [page_id] => 47iNetBet [parent_id] => 0 [name] => adam 1 [email] => web#web.de [url] => [comment] => main comment [dt] => 2012-02-23 13:05:13 [ip] => 127.0.0.1 ) **[childs]** => Array ( [2] => stdClass Object ( [self] => stdClass Object ( [id] => 2 [page_id] => 47iNetBet [parent_id] => 1 [name] => adam 2 [email] => web#web.de [url] => [comment] => 1st reply [dt] => 2012-02-23 13:05:25 [ip] => 127.0.0.1 ) **[childs]** => Array ( [3] => stdClass Object ( [self] => stdClass Object ( [id] => 3 [page_id] => 47iNetBet [parent_id] => 2 [name] => adam 3 [email] => web#web.de [url] => [comment] => 2nd reply [dt] => 2012-02-23 13:05:35 [ip] => 127.0.0.1 ) **[childs]** => Array ( ) ) ) ) ) ) )
Each comment's parent_id refers to the id of its parent. If parent_id is zero then it's a main comment. This works fine - so far I have been able to add as many nested comments as I want without any problems. But it seems that as soon as I delete something from my database or even delete all the comments and then start adding new comments (even the exact same comments ids, parent_ids etc.) at some point the structure gets messed up. Here is the same example after deleting comments from database and repopulating database with the same comments data:
Array ( [0] => stdClass Object ( **[self]** => stdClass Object ( [id] => 1 [page_id] => 47iNetBet [parent_id] => 0 [name] => adam 1 [email] => web#web.de [url] => [comment] => main comment [dt] => 2012-02-23 13:05:13 [ip] => 127.0.0.1 ) **[childs]** => Array ( [2] => stdClass Object ( [self] => stdClass Object ( [id] => 2 [page_id] => 47iNetBet [parent_id] => 1 [name] => adam 2 [email] => web#web.de [url] => [comment] => 1st reply [dt] => 2012-02-23 13:14:40 [ip] => 127.0.0.1 ) **[childs] => Array (EMPTY???) ) ) )** [1] => stdClass Object ( [childs] => Array ( [3] => stdClass Object ( [self] => stdClass Object ( [id] => 3 [page_id] => 47iNetBet [parent_id] => 2 [name] => adam 3 [email] => web#web.de [url] => [comment] => 2nd reply [dt] => 2012-02-23 13:14:47 [ip] => 127.0.0.1 ) [childs] => Array ( ) ) ) ) )
As you can see in the latter example, the second child (main comment -> reply -> reply to reply) is an empty array. What should be in this array is now put at the end as some sort of independent/incomplete comment which breaks the flow of the display. If I drop the "comments" table and start a new one everything seems to work fine again until I start deleting stuff again.
I dont know how to explain, but this is weird. I cant imagine that there is something wrong with the code as everything seems to work fine otherwise. Could this have to do anything with the database itself? Maybe someone had a similar problem? Maybe someone could point me in the right direction. I dont even know where to start looking.
Any help, suggestions would be much appreciated.
Problem solved. It was indeed an error within the code. The records in the database need to be fetched in a certain order (sorted by parent_id in ascending order). It was as simple as that.
I'm wondering if it's possible to get the name of a stylesheet from view.yml in an action, ideally using something as simple as:
sfConfig::get('......');
I'd like to access the existing declaration in view.yml instead of hardcoding it or duplicating it somewhere like app.yml.
Thanks.
If you want to access the current Module's Config, you can use:
sfViewConfigHandler::getConfiguration(array(dirname(__DIR__) . '/config/view.yml'));
It should return something like this:
Array
(
[indexSuccess] => Array
(
[javascripts] => Array
(
[0] => mission-control.js
)
[stylesheets] => Array
(
[0] => control-box.css
[1] => question.css
)
)
[newSuccess] => Array
(
[javascripts] => Array
(
[0] => box-checker.js
[1] => topic.js
)
[stylesheets] => Array
(
[0] => question.css
[1] => topic.css
)
)
[searchSuccess] => Array
(
[javascripts] => Array
(
[0] => topic.js
)
[stylesheets] => Array
(
[0] => topic.css
)
)
[showSuccess] => Array
(
[javascripts] => Array
(
[0] => mission-control.js
)
[stylesheets] => Array
(
[0] => control-box.css
[1] => question.css
)
)
[editSuccess] => Array
(
[javascripts] => Array
(
[0] => box-checker.js
[1] => topic.js
)
[stylesheets] => Array
(
[0] => question.css
[1] => topic.css
)
)
[all] => Array
(
[stylesheets] => Array
(
)
[javascripts] => Array
(
)
)
)