PHP
5. Using the function declaration below, explain whether or not the function has any errors in it, what its purpose is and any optimizations you think can be made. Be sure to include descriptions of the passed arguments and function output, if any. Be sure to state your assumptions.
1 function get_employees_by_hierarchy( $_employee_id = 0,$_depth = 0,$_org_array = array() ) {
2 if ( $this->org_depth < $_depth ) {
3 $this->org_depth = $_depth;
4 }
5 $_depth++;
6 $_query = "SELECT * FROM employees WHERE ";
7 if ( !$_employee_id ) {
8 $_query .= "employee_manager_id IS NULL OR employee_manager_id = 0";
9 }
10 else {
11 $_query .= "employee_manager_id = " . $this->dbh->quoteSmart( $_employee_id );
12 }
13 $_result = $this->query( $_query );
14
15 while ( $_row = $_result->fetchRow() ) {
16 $_row['depth'] = $_depth;
17 array_push( $_org_array, $_row );
18 $_org_array = $this->get_employees_by_hierarchy(
19 $_row['employee_manager_id'],
20 $_depth,
21 $_org_array
22 );
23 }
24 return $_org_array;
25 }
Follow Up Questions:
5. Speculate why lines 2 – 4 are necessary.
6. Speculate why line 16 is necessary.
MYSQL
Given the table structure and row data below, answer the follow up questions.
mysql> explain user_skill;
+--------------------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------------+------------------+------+-----+---------+----------------+
| user_skill_id | int(11) | | PRI | NULL | auto_increment |
| user_skill_last_modified | timestamp(14) | YES | | NULL | |
| user_skill_date_created | datetime | YES | | NULL | |
| user_id | int(11) | YES | | NULL | |
| skill_name | char(255) | YES | | NULL | |
| skill_level | char(255) | YES | | NULL | |
| skill_usage | char(255) | YES | | NULL | |
| skill_last_used | char(255) | YES | | NULL | |
| user_skill_endorsed | tinyint(1) | YES | | 0 | |
+--------------------------+------------------+------+-----+---------+----------------+
9 rows in set (0.00 sec)
mysql> *************
+--------------------+-------------------+--------------------+
| user_firstname | user_lastname | skill_name |
+--------------------+-------------------+--------------------+
| Kim | Simpson | PHP |
| Kim | Simpson | Perl |
| Kim | Simpson | Microsoft Word |
| Kim | Simpson | Microsoft Access |
| Kim | Simpson | Accounting/Billing |
| Kim | Simpson | Java |
| Kim | Simpson | SQL |
| Kim | Simpson | CSS |
| Kim | Simpson | OO Programming |
| Kim | Simpson | Microsoft Excel |
+--------------------+-------------------+--------------------+
10 rows in set (0.00 sec)
Follow Up Questions:
1. Assuming that the data stored in skill_name in the user_skill table might be repeated for different users, what changes would you make to the database to normalize the skill_name and reduce repeated storage? Show the structure of the new table(s).
2. Recreate the query that returned the 10 rows of data supplied. Speculate on tables that would be needed that are not shown here.
2. Given the following query, how could it be optimized? List all assumptions:
select c.* FROM companies AS c JOIN users AS u USING(companyid) JOIN jobs AS j USING(userid) JOIN useraccounts AS ua USING(userid) WHERE j.jobid = 123;
3. Answer the follow up questions based on the below:
explain SELECT * FROM job JOIN job_postings ON (job.jobid = job_postings.jobid) JOIN companies ON companies.companyid = job.companyid WHERE job.jobid IN (16189,1618
;
+--------------+-------+-------------------+---------+---------+-------+------+-------------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+--------------+-------+-------------------+---------+---------+-------+------+-------------+
| job | const | PRIMARY,companyid | PRIMARY | 4 | const | 2 | |
| companies | const | PRIMARY | PRIMARY | 4 | const | 2 | |
| job_postings | ref | PRIMARY | PRIMARY | 4 | const | 8 | Using where |
+--------------+-------+-------------------+---------+---------+-------+------+-------------+
3 rows in set (0.00 sec)
Follow Up Questions
Explain any optimizations that can be made to the above query.
How many rows will be analyzed by this query?
JavaScript
Given the JavaScript below, answer the follow up questions.
1 spell_img = new Image();
2 spell_img.src = '/images/standard/spellcheck.gif';
3 spell_img.setAttribute('title',_lang_spellcheck );
function find_text_boxes()
{
myforms = document.forms;
for( i=0;i < myforms.length; i++ )
{
textareas = myforms[i].getElementsById('textarea');
for( y=0; y < textareas.length; y++ )
{
spelllink = document.createElement('a');
spelllink.setAttribute('href',"javascript
:spellChe ck(" + i + ", '" + textareas[y].name + "')");
spelllink.appendChild( spell_img.cloneNode(true) );
textareaParent = textareas[y].parentNode;
textareaParent.insertBefore( spelllink, textareas[y].nextSibling );
}
}
}
Follow Up Questions:
1. Do any errors exist? If so, how would you fix them?
2. How many images will this create and where will it place them?
Perl
3. Given the following piece of code, answer the follow up questions.
1 foreach('country','city','state','desiredsalary', 'education')
2 {
3 my $loopname = $_;
4 my $global = 'D_USER'.uc($_);
5 my $hashname = 'System:
_USER'.uc($_);
6 foreach(
7 sort
8 {
9 if ($loopname =~ /education|desiredsalary/i )
10 {
11 return($a <=> $b);
12 }
13 else
14 {
15 return ($$hashname{$a} cmp $$hashname{$b});
16 }
17 }
18 keys(%{$hashname}) )
19 {
20 if ($$hashname{$_})
21 {
22 my %row={'name'=>$System::{$global}{$_},'value'=>$_};
23 $template->addlooprow($global,%row);
24 }
25 }
26 }
Follow Up Questions
1. Do any errors exist? If so, how would you fix them?
2. Based on which conditions will the keys of $hashname be sorted?
Please your answer kung kinsa tong nay answer send sako email:
datukaboskungpalad@yahoo.com pass nako ugma hapon salamat sa tanan