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 8961399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:53:00+00:00 2026-06-15T15:53:00+00:00

below is my code through which I’m trying get certain values to a drop

  • 0

below is my code through which I’m trying get certain values to a drop down box from a SQL database. I’m also trying to exclude some of the data before loading to the dropdown box.

In my code $excld[] works fine and the expected zero values are not shown when the dropdown is populated, but the values I expect to exclude via $exclude=$rec['chkNum']; doesn’t work, or else the values I dont want to be in the dropdown still shows. Can someone tell me is there anything wrong in the approach?
thanks.

$exclude = array();
$query = "SELECT * FROM invoentry WHERE dist_inv='$distUsr'";
$runx=mysqli_query($db,$query) or die ("SQL Error");
$norx=mysqli_num_rows($runx);

while ($rec = mysqli_fetch_array($runx))
{
    $exclude[] = $rec['chkNum']; $excld[] = '0';
}

$SQLx="SELECT * FROM newchk WHERE dist_chk='$distUsr'";
$runx=mysqli_query($db,$SQLx) or die ("SQL Error");
$norx=mysqli_num_rows($runx);

while ($rec = mysqli_fetch_array($runx))
    {
        if($rec['sbstart'] != '0' & $rec['sbend'] != '0') {
        for($i=$rec['sbstart']; $i<=$rec['sbend']; $i++)
        {
            if (!in_array($i, $exclude, $excld))
            {
                echo "<option id='options' value='$i'>$i<br></option>";
            }
        } }

         if($rec['gwstart'] != '0' & $rec['gwend'] != '0') {
        for($i=$rec['gwstart']; $i<=$rec['gwend']; $i++)
        {
            if (!in_array($i, $exclude, $excld))
            {
                echo "<option id='options' value='$i'>$i<br></option>";
            }
        } }
    }   

EDIT :

Database structure is as follows;
Database name :regional_data
Two tables in the same database invoentry and newchk

invoentry:

usr_inv dist_inv chkNum InvoNum
---------------------------------
John     Guardian   300455   457gXT

newchk:

usr_chk  dist_chk sbstart sbend totsb gwstart gwend totgw
----------------------------------------------------------
John     Guardian 300400  300550 151   300     310   10
  • 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-15T15:53:02+00:00Added an answer on June 15, 2026 at 3:53 pm

    I don’t see how it could work in any case (ok, in first iteration it can work, since $i is still string then). Take a look what parameters in_array accepts

    bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )

    In your case, you are passing: integer $i, array of strings $exclude (everything fetched from database is a string, unless you cast it yourself) and non empty array $excld filled with string “0”. Last argument evaluates to TRUE (array is not empty) so php is checking not only values but also types. Since you ara passing integer and array of strings, php would not find any elements inside with same type and value, so it will print all elements.

    What to change to make it work:

    while ($rec = mysqli_fetch_array($runx))
    {
        $exclude[] = $rec['chkNum']; //remove $excld[] = '0';
    }
    // add 0 to $exclude
    $exclude[] = '0';
    

    and

    if (!in_array($i, $exclude)) //remove , $excl
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying retrieve user name from the code through graph api, the below
In the below code, I am trying insert the records from excel to Database
I have the code below which loops through selected checkboxes and executes and sql
In the below code I'm trying to loop through each child node and append
I am trying to retrieve information through Facebook graph api, using the below code
I've manage to put together the below code through various examples, which seems to
I have the below code (which goes through the C: drive and gets file
I have the below code which goes through and returns disk information. When running
Using the code below I will get all network interfaces which are enabled and
I have a textbox below which is created through this code: $('#txtWeight').each( function() {

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.