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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:51:49+00:00 2026-05-25T12:51:49+00:00

I already asked this but I dont know how to fix it please help,

  • 0

I already asked this but I dont know how to fix it please help, my $obj->obtainID($a); i returns nothing for the second index.

Description:
I got an $arrayDirectoy variable which contains just 2 values, then I tried to pass that variable to a query in a for loop to retrieve the ids of each one, but It just echo me one id, and there are two ids, I dont know how to fix that, It just print me 1 id.

Example $arrayDirectory[] = {user1, user2};

it must echo 1 2 but just print me 1

for($i=0;$i<sizeof($arrayDirectory);$i++){ 
    $res[$i] = $obj->obtainID($arrayDirectory[$i]);

    echo $res[$i];

}

this is my obtainID method

public function obtainID($user){

        $conexion = $this->objConexion->configuracion();
        $query = "CALL sp_xxx('$user')";
        $stmt = $conexion->prepare($query);
        $stmt->execute();
        $resultado = $stmt->fetchColumn();
        return $res;
    }
  • 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-25T12:51:49+00:00Added an answer on May 25, 2026 at 12:51 pm

    There are a couple issues. First, you have a syntax error — you forgot a closing parenthesis to sizeof():

    for($i=0;$i<sizeof($arrayDirectory;$i++){ 
    

    Also, if you’re not changing the number of elements, there’s no need to call sizeof() more than once:

    $count = count($arrayDirectory); // or sizeof(), doesn't matter
    for($i=0; $i<$count; $i++)
    

    Lastly, you should be calling count() or sizeof() on $arrayDirectory[0], not $arrayDirectory. This is because the array only has one element, which happens to be an object that contains two fields. Alternatively, it probably makes sense for $arrayDirectory to just be an object, not an array.

    So, your final code should look like:

    $arrayDirectory = {'user1', 'user2'};
    $count = count($arrayDirectory); // or sizeof(), doesn't matter
    for($i=0; $i<$count; $i++) 
        $res[$i] = $obj->obtainID($arrayDirectory[$i]);
        echo $res[$i];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know a question like this was already asked, but the situation is a
I know that this has already been asked here but the answer (using a
I know this question has probably been asked already but I would really like
I know this question has already been asked but I am in urgent need
I already asked this question at the JOS-.NET board but Joel is closing that
I am sorry I have already asked this question on Superuser, but nobody answers
Apologies if this was already asked but, I have had a look and can't
I've seen this question asked already - but none of the answers really gelled
Searching here I found that this question was already asked , but I think
I'm sorry if this question has been asked already, but I couldn't find it

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.