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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:52:06+00:00 2026-05-23T09:52:06+00:00

Please review this code: $current_sql = mysql_query(SELECT * FROM `product_categories` WHERE `product`='{$_GET[‘id’]}’); $all_sql =

  • 0

Please review this code:

    $current_sql = mysql_query("SELECT * FROM `product_categories` WHERE `product`='{$_GET['id']}'");
    $all_sql = mysql_query("SELECT * FROM `categories`");
    $in = mysql_fetch_array($current_sql);

    while($ca = mysql_fetch_array($all_sql)){

        echo("<label><input type=\"checkbox\" name=\"categories[]\" value=\"".$ca['ID']."\" class=\"cat_check\"");
        if($edit){
            if(in_array($ca['ID'], $in)){
                echo(" checked=\"checked\"");   
            }
        }
        echo("> " . $ca['category'] . "</label><br/>\n");

    }

This is the output:

<label><input type="checkbox" name="categories[]" value="1" class="cat_check" checked="checked"> PS3 Games</label><br/> 
<label><input type="checkbox" name="categories[]" value="16" class="cat_check"> Category 2</label><br/> 
<label><input type="checkbox" name="categories[]" value="17" class="cat_check" checked="checked"> Category 3</label><br/> 
<label><input type="checkbox" name="categories[]" value="18" class="cat_check"> Category 4</label><br/> 
<label><input type="checkbox" name="categories[]" value="19" class="cat_check"> Category 5</label><br/>

The problem is only checkbox value=”17″ is supposed to be checked, there are 2 MySQL databases here are are the structures:

categories:

ID    |   name
1         PS3 Games
16        Category 3
17        Category 4
18        Category 5
19        Category 6

product_categories

category     |    product
1                 20
17                1

Please help!!

UPDATE:

Sorry forgot to add:

$_GET['id'] = 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-23T09:52:07+00:00Added an answer on May 23, 2026 at 9:52 am

    Instead

    $in = mysql_fetch_array($current_sql);
    

    do

    while ($prod_cat = mysql_fetch_array($current_sql)) {
      $in[] = $prod_cat['cat_id']; // where cat_id is the category ID in product_categories table
    }
    

    Basically the problem is that mysql_fetch_array get you back 2 arrays and I guess that you have something like array([0] = 1, [1] =17, etc ...). This is causing both categories to be checked. If you print_r the $in in your code, you will see what I mean.

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

Sidebar

Related Questions

I'm using this code: Dim VehiclesTable1 = dsVehicleList.Tables(0) Dim VT1 = (From d In
Please consider this example class: [Serializable] public class SomeClass { private DateTime _SomeDateTime; public
Please, provide code examples in a language of your choice. Update : No constraints
When I upload the image it is showing this error please can u help
So I have a grid view with checkboxes in it. This is the code
I have this call: List<Product> featProducts = productsRepository.Products.Where(x => x.Featured == true).ToList(); It returns
I am getting this error on a remote server, but the same code executes
Please look at the following code: client.Credentials = new NetworkCredential(SMTP_SERVER_USERNAME, SMTP_SERVER_PASSWORD); client.EnableSsl = false;
I have a SQL query like this: SELECT E.HESAP, B.TEKLIF_NO1 + '/' + B.TEKLIF_NO2
ASP.NET application performing oAuth with Facebook. This code was working fine until a few

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.