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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:00:31+00:00 2026-06-04T08:00:31+00:00

What I’m trying to accomplish is a back-end Admin panel, with multiple forms to

  • 0

What I’m trying to accomplish is a back-end Admin panel, with multiple forms to edit tables from a database.

I would like to run one SQL query on the page, & refer to it multiple times (possibly creating 3 different loops out of this same query, without having to query it more than once).

I can’t figure out how to make the query work outside of its initial loop, if possible at all.

I already have the SQL statement that would work on all the forms (since basically my forms just query the same 2 tables over & over again), but I can’t use it more than once…
I already tried it, but can’t get it to work.

I just want to run this query once, & simply refer back to it whenever I need to use it again on the page. (Perhaps by creating a new while loop? Tried it, doesn’t work. Use different variables? Doesn’t work. I’m itching to find out what DOES…)

This Admin panel is a single PHP page, divided by compartments based on administrative tasks.

For some idea, it is like so ~


// UPLOAD PHOTO //

(options available are…)
– Upload photo
– Add Photo Title
01. Select Category || SQL QUERY! LOOP – Drop-down list of Categories
02. Select Sub-categories || SQL QUERY! LOOP – Checkbox list of Categories + Sub-categories
– Add Tags
– Add Photo Description / Commentary

// MANAGE CATEGORIES //

(options available are…)
– Create a new Category
03. Delete Multiple Categories || SQL QUERY! LOOP – Checkbox list of Categories + # of entries each
04. Rename Category || SQL QUERY! LOOP – List of Categories
05. Edit Sub-Category || SQL QUERY! LOOP – List of Sub-categories


So on & so forth…
As you can see, all queries made are related to Categories.

I actually have completed a working version of this but one with too many SQL queries on just a single page (for the exact same tables over & over again), it just seems impractical and thoughtless. There has got to be a better way…

The query I’d like to use just once (& the one I’m using right now) is:

$sql = "SELECT category.id, category.name, COUNT(records.category_id) as number
FROM category
    LEFT OUTER
        JOIN records
        ON category.id = records.category_id
WHERE
    category.active = 1
GROUP
    BY category.id
ORDER
    BY category.name";
$result = mysql_query($sql);

while($rows = mysql_fetch_array($result)) {
    echo "SAMPLE LOOP" . $rows['id'] . $rows['name'] . $rows['number']; }

Is there a way to achieve what I am trying to achieve?
Thank you for your time and wisdom!

  • 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-04T08:00:35+00:00Added an answer on June 4, 2026 at 8:00 am

    Save the results to a new array and you can then iterate over that when you need to:

    $sql = "SELECT category.id, category.name, COUNT(records.category_id) as number
    FROM category
        LEFT OUTER
            JOIN records
            ON category.id = records.category_id
    WHERE
        category.active = 1
    GROUP
        BY category.id
    ORDER
        BY category.name";
    $result = mysql_query($sql);
    $saved_results = array();
    while($rows = mysql_fetch_array($result)) {
        echo "SAMPLE LOOP" . $rows['id'] . $rows['name'] . $rows['number']; 
        array_push($saved_results, $rows);
    }
    

    Then whenever you want:

    foreach($saved_results as $res) {
      dostuff();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

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
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.