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

  • Home
  • SEARCH
  • 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 6885871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:41:20+00:00 2026-05-27T05:41:20+00:00

All, I have the following code: $qry = Select * from vendor_options order by

  • 0

All,
I have the following code:

$qry = "Select * from vendor_options order by vendor_option_name ASC";
$result = mysql_query($qry);
while($resultset = mysql_fetch_array($result)){
    if(isset($_SESSION['pav_choosen_vendor_categories'])){
        for($z=0;$z<$_SESSION['pav_choosen_vendor_categories'];$z++){
            $sVendorId = $_SESSION['pav_vendor_categories_' . $z];
                if($sVendorId==$resultset['vendor_option_id']){
                    $vendor_cats_choosen[] = $sVendorId;
                }
        }
        if(in_array($resultset['vendor_option_id'],$vendor_cats_choosen)){
        ?>
        <input type="checkbox" value="<?php echo $resultset['vendor_option_id']; ?>" class="select_vendor" name="vendor_categories[]" checked><?php echo $resultset['vendor_option_name']; ?><br>
            <?php
        }else{
        ?>
        <input type="checkbox" value="<?php echo $resultset['vendor_option_id']; ?>" class="select_vendor" name="vendor_categories[]"><?php echo $resultset['vendor_option_name']; ?><br>
        <?php
        }
    }
}

I’m trying to check to see if the value returned in the mysql_fetch_array is already in my array. Say the first value it finds in the array is in the fourth iteration of the while loop. I’ll get the following error:

Warning: in_array() expects parameter 2 to be array, null

Once it gets to a value that is in the array the rest of them work fine. Why does itgive an error for the first couple? Thanks.

  • 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-05-27T05:41:20+00:00Added an answer on May 27, 2026 at 5:41 am

    It looks like you have not initialized $vendor_cats_chosen to be an array, and so if the condition if($sVendorId==$resultset['vendor_option_id']) is not true, no elements will be appended to it, turning it implicitly into an array.

    Initialize it before the while loop. You should just about always initialize arrays before use.

    // Initialize the array
    $vendor_cats_chosen = array();
    while($resultset = mysql_fetch_array($result)){
      ....
    

    Now, when your in_array() statement executes, the array may be empty, but will be a valid array.

    // $vendor_cats_chosen might be an empty array, or may have elements.
    if(in_array($resultset['vendor_option_id'],$vendor_cats_choosen)){
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which I got from http://css-tricks.com/startstop-slider/ I have it all
I have the following code: Query query = this.getSession().createSqlQuery(select * from db@server:table where 1=1);
i have following code: SELECT * FROM table WHERE thread = $thread AND (user
I have following code: SELECT q21, q21coding AS Description FROM `tresults_acme` WHERE q21 IS
I have the following code to zip all the files and then save it
I have the following code: // Obtain the string names of all the elements
I have the following code to assign a value to all the elements of
i have the following code def get(self): date = datetime.date.today() loc_query = Location.all() last_cursor
I have following statement for query articles from some sections Article.all(:joins => :sections, :conditions
I was given the following code: class FibHeapNode { //... // These all have

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.