Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Displays Profiles with a Similar Job Title and Industry in php

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 402
    Answer it

    What I want:

    When I click the First Name a profile.php will open and in one place of a profile.php displays Profiles with a Similar Job Title and Industry

    Example

    Click Steven and Neena, Lex, and Alexander's profile will display in profile.php because their job title is the same as Steven. Display First and Last name and their company name

    Sample table: employees

    +--------+-----------+-----------+----------+--------------+------------+-----------+
    | cempid | FName     | LName     | EMAIL    | PHONE_NUMBER | title      | companyID |
    +--------+-----------+-----------+----------+--------------+------------+-----------+
    |    100 | Steven    | King      | SKING    | 515.123.4567 | IT_PROG    | 1241      |
    |    101 | Neena     | Kochhar   | NKOCHHAR | 515.123.4568 | IT_PROG    | 1241      |
    |    102 | Lex       | De Haan   | LDEHAAN  | 515.123.4569 | IT_PROG    | 1241      |
    |    103 | Alexander | Hunold    | AHUNOLD  | 590.423.4567 | IT_PROG    | 1241      |
    |    104 | Bruce     | Ernst     | BERNST   | 590.423.4568 | FI_MGR     | 1242      |
    |    105 | David     | Austin    | DAUSTIN  | 590.423.4569 | FI_MGR     | 1242      |
    |    106 | Valli     | Pataballa | VPATABAL | 590.423.4560 | FI_MGR     | 1242      |
    |    107 | Diana     | Lorentz   | DLORENTZ | 590.423.5567 | IT_PROG    | 1242      |
    |    108 | Nancy     | Greenberg | NGREENBE | 515.124.4569 | FI_ACCOUNT | 1300      |     
    |    109 | Daniel    | Faviet    | DFAVIET  | 515.124.4169 | FI_ACCOUNT | 1300      |
    |    110 | John      | Chen      | JCHEN    | 515.124.4269 | FI_ACCOUNT | 1300      |
    +--------+-----------+-----------+----------+--------------+------------+-----------+
    
    Sample table: company
    
    +-------------------+----------+---------+--------+-------+-----+------------+
    | CompanyName       | scat_id  | Address | City   | State | Zip | companyID  |
    +-------------------+----------+---------+--------+-------+-----+------------+
    | SAGEM SA          | 111      |         |        |       |     | 1241       |
    | Aguila Ammunition | 112      |         |        |       |     | 1242       |
    +-------------------+----------+---------+--------+-------+-----+------------+

     

    What I am tried

    <?php
                                require_once 'tabconnect.php';
                                    if (isset($_GET['id'])) {
                                        $id = $_GET['id'];
                                            $query1 = mysqli_query($connection,"SELECT cemployees.cempid,cemployees.FName,cemployees.companyID,cemployees.title,company.CompanyName FROM cemployees JOIN company ON company.companyID=cemployees.companyID WHERE cemployees.cempid='id' OR cemployees.spcode='PMS' LIMIT 5");
                                                while ($row2 = mysqli_fetch_array($query1)) {
                            ?>
                                                <!-- Displaying Data Read From Database -->                                     
                                                    <?php echo $row2['FullName']; ?><br>
                                                                                                <span class="profilePage-profileSection_info-company"><?php echo $row2['CompanyName']; ?></span><hr style=" border: transparent">
    
    
                            <?php
                                    }
                                    }
                            ?>
    
    I tried to add one code

     

 1 Answer(s)

  • Hi GBose,
    You just need to use another query to get all the employees with same title. Put following section inside your current while loop:
    $query2 = mysqli_query($connection, "SELECT cemployees.cempid, cemployees.FName,cemployees.companyID, cemployees.title, company.CompanyName FROM cemployees JOIN company ON company.companyID = cemployees.companyID WHERE cemployees.title='".$row2['title']."' LIMIT 5");
       while ($relatedEmployees = mysqli_fetch_array($query2)) {
          //Echo your required fields here
       }
    Also if employee should be from same company then you don't need to use JOIN and can directly add companyID condition:
    $query2 = mysqli_query($connection, "SELECT cemployees.cempid, cemployees.FName,cemployees.companyID, cemployees.title FROM cemployees WHERE cemployees.title='".$row2['title']."' AND cemployees.companyID=".$row2['companyID']." LIMIT 5");
    Get CompanyName from $row2 variable as all of them from same company.
    Let me know if it works.
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: