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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:18:57+00:00 2026-06-02T12:18:57+00:00

I keep getting a wierd list after running this: <?php $query_Category = SELECT *

  • 0

I keep getting a wierd list after running this:

<?php 
  $query_Category = "SELECT * FROM blog_categories ORDER BY category ASC";

  $getCategory = mysql_query($query_Category) or die(mysql_error()); 
?>

<div id="sheader" style="">Categories</div>

<div class="sbody" style="color:#000 !important;">

<?php 
   do { 
?>
    <div><?php echo $row_getCategory['category'];?></div>

<?php 
    $cat = $row_getCategory['cat_id'];

    $query_Subcategory = "SELECT * FROM blog_subcategories WHERE primcat_id = '$cat' ORDER BY subcategory ASC";

    $getSubCategory = mysql_query($query_Subcategory) or die(mysql_error());
    $row_getSubCategory = mysql_fetch_assoc($getSubCategory);

    $str = $row_getSubCategory['subcategory']; $subcategory = explode(',', $str);

    foreach ($subcategory as $arraysubcat) 
    {
       echo '<div>' . $arraysubcat . '</div>';
    }
    } while ($row_getCategory = mysql_fetch_assoc($getCategory)); 
?>

</div>
<?php mysql_free_result($getCategory); ?>

I have a categories table with id & category and a sub categories table with a id, subcategory, & primary category id.
I run it and it displays the foreach first randomly.

  • 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-02T12:19:06+00:00Added an answer on June 2, 2026 at 12:19 pm

    I think you should not use do while to retrieve the data from the database.You should rather use while loop because, do while runs the loops once before checking the condition.So at the first loop, you will not get any data in the echo $row_getCategory['category']; variable. So please try using the following code :

    <?php
    while ($row_getCategory = mysql_fetch_assoc($getCategory)){
    ?>
            <div>
              <?php
                echo $row_getCategory['category'];      
               ?>
            </div>
            <?php
                $cat = $row_getCategory['cat_id'];
    
                $query_Subcategory = "SELECT * FROM blog_subcategories WHERE primcat_id = '$cat' ORDER BY subcategory ASC";
    
                $getSubCategory = mysql_query($query_Subcategory) or die(mysql_error());
                $row_getSubCategory = mysql_fetch_assoc($getSubCategory);
    
                $str         = $row_getSubCategory['subcategory'];
                $subcategory = explode(',', $str);
    
                foreach ($subcategory as $arraysubcat) {
                    echo '<div>' . $arraysubcat . '</div>';
                }
            ?>
    <?php
    } 
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Keep getting this error after inserting a subdatasheet into a query and trying to
I keep getting this error from my code and I have no idea what
I keep getting this weird output from my code everytime I use the 'start
I keep getting this error saying that it cannot find my javascript function checkpw().
I keep getting an syntax error during runtime when this query is called. adoquery1.Active
I keep getting this error and i have been trying everything for about a
I'm trying to implement adaptive payments but keep getting this weird error. Here's the
I keep getting a 400 bad request code from a hotfile.com page when I
What am I doing wrong? I keep getting weird errors from SQL? //get parameters
I keep getting this weird error message every time I'm testing my app on

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.