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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:10:31+00:00 2026-06-15T00:10:31+00:00

So, this is an odd thing I have encountered and maybe it’s because of

  • 0

So, this is an odd thing I have encountered and maybe it’s because of the late night or I am just missing something basic here. I have to send the query to array instead of looping over the query because other API calls can send the array instead of coming from the DB. The query returns multiple items as it’s supposed too. On to the code:

$result = $db->query("SELECT ID FROM tblTemp WHERE FOREIGN_KEY='2'");
$tmp = $result->fetch_array(MYSQLI_BOTH);        

for($i = count($tmp); $i > 0; --$i) {
echo '<option value="'.$tmp[$i-1].'">Item '.$i.'</option>';
}

So, I am simply trying to get the array items into a HTML select. This works fine for passed $tmp arrays; however, what happens when you use the query is, that only the first record is populated in the select. The correct amount of items is added, but the values are missing.
i.e.

<option value="">Item 2</option>
<option value="7">Item 1</option> 

EDIT: PHP does throw an error of: Undefined offset: 1

  • 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-15T00:10:33+00:00Added an answer on June 15, 2026 at 12:10 am

    You’re only fetching one record from query, that’s why you have one value and get an Undefined offset.
    In the following example a while loop is used to fetch all the results from the query.

    $result = $db->query("SELECT ID FROM tblTemp WHERE FOREIGN_KEY='2'");
    $html = "";
    $i = 1;
    while($tmp = $result->fetch_array(MYSQLI_BOTH)) {
        $html = '<option value="'.$tmp['ID'].'">Item '.$i.'</option>'.html;
        $i++;
    }
    echo $html;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an odd thing I've just run into. I have a web application
I just saw a very odd thing, I have a co-worker who has their
I ran into something odd today that maybe someone knows something about. I have
Can someone explain to me this odd thing: When in python shell I type
I have been banging my head against the wall with this odd behaviour on
This is odd. I have a Default.png, Default-Landscape.png, Default-Portrait.png and Default@2x.png. The normal default
I ran into something a little odd this morning and thought I'd submit it
So, this is odd. In my makefile I have CC:=icc ifeq ($(CC),icc) CFLAGS :=
match.matches() returns false. This is odd, because if I take this regex and test
Admittedly, this is a strange problem for me to have, but here is what

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.