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

  • Home
  • SEARCH
  • 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 5978623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:32:33+00:00 2026-05-22T21:32:33+00:00

I have a code like this <?php $getLeftSide = ‘select * from leftmenu’; $result

  • 0

I have a code like this

<?php

$getLeftSide = 'select * from leftmenu';

$result = $db -> query ($getLeftSide) or die ("$db->error");

if ($result) {

    while ($row = $result -> fetch_object()) {

        $getCat = $row -> left_item_cat;



        if ($getCat == 1) {
    echo "<div class='left_main_cat'>Web and Desigen</div>";
    echo "<a href='index.php?learn_id= $row->left_item_link'><div class='left_label_sub'>$row->left_item_name</div></a>";

        }
      }
    }



?>

I need to echo this line one time

echo "<div class='left_main_cat'>Web and Design</div>";

of course it’s under the while loop so it print it self many times
is there is a why to solve this and print this line one time only.

  • 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-22T21:32:34+00:00Added an answer on May 22, 2026 at 9:32 pm

    As Ben suggests, the easiest and clearest solution is to use a boolean check variable:

    $catFound = FALSE;
    while ($row = $result -> fetch_object()) {
    
        $getCat = $row -> left_item_cat;
    
        if ($getCat == 1) {
            // We only want this category printed for the first category,
            // if it exists.
            if(!$catFound) { 
                echo "<div class='left_main_cat'>Web and Desigen</div>";
                $catFound = TRUE;
            }
            echo "<a href='index.php?learn_id= $row->left_item_link'><div class='left_label_sub'>$row->left_item_name</div></a>";
        }
    }
    

    Although it seems better to use a boolean variable and a comment to make clear your intent.

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

Sidebar

Related Questions

I have my php code like this: $products = mysql_query(SELECT p.* FROM products AS
Let's say I have some code like this: <html> <head><title>Title</title></head> <body> <?php if (!$someCondition){
In PHP, say that you have some code like this: $infrastructure = mt_rand(0,100); if
I have a bit of php code like this: $test = <!--my comment goes
I currently have code like this in a web based file called 'view_file.php' to
I have a dynamic input in my php code like this one: <input type=checkbox
I have this PHP code echo '<a href=# onclick=updateByQuery(\'Layer3\', ' . json_encode($query) . ');>Link
I have written a PHP Script, I run the code like this on MS-DOS
I have code like this: <?php echo '<script type=text/javascript>'; echo 'var out='.$txt.';'; echo '</script>';
I have a code like this: ORDER BY $order Where '$order' is taken from

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.