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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:55:24+00:00 2026-05-13T22:55:24+00:00

I’d like to print a simple table in my page with 3 columns, building

  • 0

I’d like to print a simple table in my page with 3 columns, building name, tags and architecture style. If I try to retrieve the list of building names and arch. styles there is no problem:

SELECT buildings.name, arch_styles.style_name
FROM buildings
INNER JOIN buildings_arch_styles
ON buildings.id = buildings_arch_styles.building_id
INNER JOIN arch_styles
ON arch_styles.id = buildings_arch_styles.arch_style_id
LIMIT 0, 10

My problem starts on retreaving the first 5 tags for every building of the query I’ve just wrote.

SELECT DISTINCT name
FROM tags
INNER JOIN buildings_tags
ON buildings_tags.tag_id = tags.id
AND buildings_tags.building_id = 123
LIMIT 0, 5

The query itself works perfectly, but not where I thought to use it:

<?php

// pdo connection allready active, i'm using mysql
$pdo_conn->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);

$sql = "SELECT buildings.name, buildings.id, arch_styles.style_name
        FROM buildings
        INNER JOIN buildings_arch_styles
        ON buildings.id = buildings_arch_styles.building_id
        INNER JOIN arch_styles
        ON arch_styles.id = buildings_arch_styles.arch_style_id
        LIMIT 0, 10";

$buildings_stmt = $pdo_conn->prepare ($sql);
$buildings_stmt->execute ();
$buildings = $buildings_stmt->fetchAll (PDO::FETCH_ASSOC);

$sql = "SELECT DISTINCT name
        FROM tags
        INNER JOIN buildings_tags
        ON buildings_tags.tag_id = tags.id
        AND buildings_tags.building_id = :building_id
        LIMIT 0, 5";
$tags_stmt = $pdo_conn->prepare ($sql);

$html = "<table>"; // i'll use it to print my table

foreach ($buildings as $building) {
    $name = $building["name"];
    $style = $building["style_name"];
    $id = $building["id"];

    $tags_stmt->bindParam (":building_id", $id, PDO::PARAM_INT);
    $tags_stmt->execute (); // the problem is HERE
    $tags = $tags_stmt->fetchAll (PDO::FETCH_ASSOC);

    $html .= "... $name ... $style";

    foreach ($tags as $current_tag) {
        $tag = $current_tag["name"];
        $html .= "... $tag ..."; // let's suppose this is an area of the table where I print the first 5 tags per building
    }

}
$html .= "...</table>";
print $html;

I’m not experienced on queries, so i though something like this, but it throws the error:

PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.

What can I do to avoid this? Should I change all and search a different way to get this kind of queries?

  • 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-13T22:55:25+00:00Added an answer on May 13, 2026 at 10:55 pm

    You say that you posted a simplified version of the code. Did you change anything else when you posted it here? This error is normally caused when you have multiple queries “open” at the same time. For example, you call fetch(), but you don’t call it until it’s depleted, and then you try to retrieve a second query.

    Judging by your code above, this shouldn’t happen because you’re using fetchAll(). Normally, the solution to this problem is to call closeCursor() [docs]. You could try calling that after each fetchAll and see if that does anything.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm making a simple page using Google Maps API 3. My first. One marker
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.