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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:42:37+00:00 2026-05-21T12:42:37+00:00

I ran into this problem earlier but I didn’t ask it because I found

  • 0

I ran into this problem earlier but I didn’t ask it because I found a work around, however Im not so lucky this time.

I am trying to create a simple list for each “pg.pcat” (page category) to show 5 latest links from each category (I am aware I didn’t add LIMIT or ORDER BY).

$q2 = "
SELECT pg.pcat, p.page_id, p.link_title 
FROM pages AS P 
INNER JOIN page_categories AS pg ON pg.pc_id = $sidenav
";

$r2 = @mysqli_query ($dbc, $q2); // Run the Query.  

while ($qarr = mysqli_fetch_array($r2, MYSQLI_ASSOC)) {
    if(!isset($printed)) { 
        echo "<div class=\"sideNavSpan\">{$qarr['pcat']}</div>";
        $printed = true;
    }
    echo "
    <li>
     <a href=\"page.php?pid={$qarr['page_id']}\">{$qarr['link_title']}</a>
    </li>
    ";
}

I need something like this but I can’t figure out how to use a for loop on the values in $qarr.

----pg.pcat1
p.link_title
p.link_title
p.link_title
p.link_title
p.link_title

----pg.pcat2
p.link_title
p.link_title
p.link_title
p.link_title
p.link_title

----pg.pcat3
p.link_title
p.link_title
p.link_title
p.link_title
p.link_title

etc.
help? please and thank you 🙂

  • 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-21T12:42:38+00:00Added an answer on May 21, 2026 at 12:42 pm

    You’ll need to order by pg.pcat in your SQL query, and wrap the whole of this in an if test to ensure that at least one row has been returned

    $currCat = '';
    $printed = false;
    while ($qarr = mysqli_fetch_array($r2, MYSQLI_ASSOC)) {     
       if($currCat != $qarr['pcat']) {  // category has changed
          if ($printed) { // we already printed an opening <ul> so we need to close it
             echo '</ul>';
             $printed = true;
          }
          echo"<div class=\"sideNavSpan\">{$qarr['pcat']}</div><ul>";
          $currCat = $qarr['pcat'];
       }
       echo "<li><a href=\"page.php?pid={$qarr['page_id']}\">{$qarr['link_title']}</a></li>";
    }
    echo '</ul>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This originally was a problem I ran into at work, but is now something
I know this question has been asked before, but I ran into a problem.
Today, I ran into this weird problem with a user using Mac OS X.
I'm writing a C parser using PLY, and recently ran into a problem. This
I've actually solved this, but I'm posting it for posterity. I ran into a
Ran into this problem today, posting in case someone else has the same issue.
I ran into this problem at my old job, and now again at my
Never ran into this problem with jQuery before. I have the following: $(document).ready(function() {
I have ran into this problem a few times and I am wondering what
Probably everyone ran into this problem at least once during development: while(/*some condition here

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.