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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:00:03+00:00 2026-05-13T16:00:03+00:00

I have an issue, I’m looping threw a set of values and then creating

  • 0

I have an issue, I’m looping threw a set of values and then creating a PDO mySql query with every loop, now the problem is the first query is executing and returning results, but the second upwards aren’t returning results. If I manually execute the queries on the server they return results. This is weird, maybe I’m doing something wrong here. My code below

if($num_results > 0){
 for($i=0;$i<$num_results;$i++){
   $sql_sub = "SELECT * FROM menu_config WHERE client_id =".$client_id ." AND id =".$data[$i]['root_menu_id'];

                    $results_s = $pdo->query($sql_sub);

                    $data_s = $results_s->fetchAll(PDO::FETCH_ASSOC);

                    $sub_menu_title = "<strong>".$data[$i]['title']."</strong>";

                    if(empty($data_s[0]['title'])){
                        $main_menu_title = '<span style="color:#FF0000;font-weight:bold;">No Main Menu Assigned to Sub Menu</span>';
                    }else{
                        $main_menu_title = $data_s[0]['title'];
                    }
                    $men_title = $data[$i]['title']
 }
}
  • 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-13T16:00:04+00:00Added an answer on May 13, 2026 at 4:00 pm

    (this may be a little more than you asked for)

    You seem to be missing out on some good things that prepared statements do.

    First off, you don’t usually want to pass the values directly into the query. (sometime’s it’s necessary, but not here). By doing that, you take out all the good stuff that protects from sql injection. Instead you want to send them as parameters after you’ve prepared the query.

    Secondly, when in a loop, you can save yourself time and resources if you’re running the same query over and over by preparing the statement, and then only changing the values you send to to that prepared statement using the PDOStatement::bindParam() function.

    Thirdly, fetchAll() does not take a ‘fetch_style’ of PDO::FETCH_ASSOC. fetch() does. But I think you can get by with the default or none using fetchAll. You’ll have to check into that and see what you need. Here are the fetchAll docs

    $sql_sub = "SELECT * FROM menu_config WHERE client_id = :client_id AND id = :id ";
    $query = $pdo->prepare($sql_sub);
    for($i=0;$i<$num_results;$i++){
       $query->bindParam(':client_id', $client_id);
       $query->bindParam(':id', $data[$i]['root_menu_id']);
       $query->execute();
    
       $data_s = $query->fetchAll();
       $sub_menu_title = "<strong>".$data[$i]['title']."</strong>";
    
       if(empty($data_s[0]['title'])){
          $main_menu_title = '<span style="color:#FF0000;font-weight:bold;">
                No Main Menu Assigned to Sub Menu</span>';
       }else{
          $main_menu_title = $data_s[0]['title'];
       }
    
       $men_title = $data[$i]['title'];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an issue with the way we are creating a Mutex . The
Much of my sql code is generated (from POD). Now i have issue where
I have an issue with the MySQL SOURCE command. I am getting the following
I have an issue that is driving me a bit nuts: Using a UserProfileManager
We have an issue using the PEAR libraries on Windows from PHP . Pear
We have an issue related to a Java application running under a (rather old)
We have an issue on our page whereby the first time a button posts
I have some issue with a Perl script. It modifies the content of a
I have an issue with using AWK to simply remove a field from a
I have big issue with url-rewriting for IIS 7.0. I've written simple module for

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.