Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8358047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:40:37+00:00 2026-06-09T10:40:37+00:00

Can anybody see what I am doing wrong here? I am trying to include

  • 0

Can anybody see what I am doing wrong here?
I am trying to include a certain page depending on the value of a field in database.

I have 2 tables to check,

if username appears in table.1 and field.units = days inlcude days.php

if username appears in table.1 and field.units = hours inlcude hours.php

if username appears in table.2 and field.units = days inlcude days.php

if username appears in table.2 and field.units = hours inlcude hours.php

   $username = $USER->firstname.' '.$USER->lastname;

    echo $username;

    $is_academic_result = mysql_query('SELECT * from holiday_entitlement_academic where employee = '.$username.'');
    $is_business_result = mysql_query('SELECT * from holiday_entitlement_business_manual where employee = '.$username.'');

    if(mysql_num_rows($is_academic_result) > 0){
    while($is_academic = mysql_fetch_array($is_academic_result)) {
    if ($is_academic['units'] == 'days'){include('days.php');}
    else if ($is_academic['units'] == 'hours'){include('hours.php');}
    }
    }

    else if(mysql_num_rows($is_business_result) > 0){
    while($is_business = mysql_fetch_array($is_business_result)) {
    if ($is_business['units'] == 'days'){include('days.php');}
    else if ($is_business['units'] == 'hours'){include('hours.php');}
    }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:40:38+00:00Added an answer on June 9, 2026 at 10:40 am

    First of all, you don’t need to do any of these operations in while loops, since there will only ever be one or zero results returned (you’re checking the primary key, right?).

    Secondly, your query isn’t set up correctly – you’re using single-quotes but never escaping them.

    So, with that in mind, we do the following:

    $is_academic_result = mysql_query('SELECT * from holiday_entitlement_academic where employee = \'' . $username . '\'');
    $is_business_result = mysql_query('SELECT * from holiday_entitlement_business_manual where employee = \'' . $username . '\'');
    
    if($is_academic = mysql_fetch_array($is_academic_result)) {
        switch($is_academic['units']) {
            case 'days':
                include_once('days.php');
                break;
            case 'hours':
                include_once('hours.php');
                break;
            default:
                break;
        }
    } else if ($is_business = mysql_fetch_array($is_business_result)) {
        switch($is_business['units']) {
            case 'days':
                include_once('days.php');
                break;
            case 'hours':
                include_once('hours.php');
                break;
            default:
                break;
        }
    }
    

    PLEASE NOTE You should stop using mysql_* functions. They’re being deprecated. Instead use PDO (supported as of PHP 5.1) or mysqli (supported as of PHP 4.1). If you’re not sure which one to use, read this SO article.

    EDIT If you’re unsure where the problem lies, you can always echo your query to make sure you’re passing what you think you’re passing to the database (more often than not, when a query isn’t working, it’s either this, or your logic is bad).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anybody see what is wrong with this code. it does not show up
Can anybody help me how can I invoke a JSP page from a Servlet
Can anybody give me a little advice please? I have a string, for example
Hi I'm trying to evaluate an NSString to see if it fits a certain
Can anybody give any working example of how to read/write Unicode text files using
Can anybody please tell me why the removeEventListener call is not working? this.addEventListener(Event.ENTER_FRAME, eventCall,
Can anybody show with some examples the exact difference between .. and ... operator?
Can anybody tell me what is the difference between standard iOS account and enterprise
Can anybody please help me with a link or document to run jbpm-5.2 on
Can anybody tell the working of overriding and hiding in terms of memory and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.