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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:58:51+00:00 2026-05-21T14:58:51+00:00

I am new to php-mysql. Can somebody help on the issue below? If so,

  • 0

I am new to php-mysql. Can somebody help on the issue below? If so, please explain a bit so that I can learn. Thanks in advance.

$data=mysql_query("SELECT tbl_category.*, tbl_product.* FROM tbl_category LEFT JOIN tbl_product ON tbl_category.cat_id=tbl_product.cat_id ORDER BY tbl_category.cat_id");
$color="1";
while($fetch=mysql_fetch_array($data, MYSQL_ASSOC)){ 

if($fetch['cat_name'] != $category){  //this returns error: "Notice: Undefined variable: category in /.../filename.php on line [this line number]
    $catdes = $fetch['pd_description'];
    echo "<tr bgcolor='#A9F5F2'><td colspan=\"2\"><div align=\"center\"><br/><b>". $fetch['cat_name']."</b><br /><span class=\"itemdescription\">". $catdes."</div></div></td></tr>";
    $category = $fetch['cat_name'];
}

    $item = $fetch['pd_name']; 
    $desc = $fetch['pd_description'];
    $price = $fetch['pd_price'];
    if($color==1){
        echo "<tr bgcolor='#FFFFFF'>";
        echo "<td width=\"93%\"><div align=\"left\">";
        echo $item . "<br /><span class=\"itemdescription\">";
        echo $desc ;
        echo "</div></td><td width=\"7%\" VALIGN=\"top\" ALIGN=\"right\"><div align=\"right\">"; 
        echo $price ."</div></td><tr>";
    $color="2";
    }
    else{
        echo "<tr bgcolor='#F2F2F2'>";
        echo "<td width=\"93%\"><div align=\"left\">";
        echo $item . "<br /><span class=\"itemdescription\">";
        echo $desc ;
        echo "</div></td><td width=\"7%\" VALIGN=\"top\" ALIGN=\"right\"><div align=\"right\">"; 
        echo $price ."</div></td><tr>";
    $color="1";
    }
}
  • 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-21T14:58:52+00:00Added an answer on May 21, 2026 at 2:58 pm

    That notice you received is the result of not declaring a variable before using it. It’s always good practice to declare your variables before using them.

    In your case you need to declare $category before comparing a value to it:

    $category = '';
    if($fetch['cat_name'] != $category){
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to php/MySQL and I'm having a bit of trouble. Help would
I am pretty new to PHP and MySQL and I just can't figure this
MySQL connection in PHP can be established in two ways: $mysql = new mysqli('localhost',
Alright, so I'm fairly new to PHP and SQL/MySQL so any help is appreciated.
Right, i'm new to PHP and mySQL, but i've got a few questions that
I am new to PHP and MySQL, can I get a smiple example of
i am new to php and mysql. How can i extract a VALUE from
Hi i'm new to php and mysql. I'm wondering how can i use PHP
I was reading my new php and MySQL book and it said that if
In a private messaging system built with PHP and MySQL users can compose new

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.