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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:27:15+00:00 2026-06-01T23:27:15+00:00

I have this table, ——————————————– | products_id | related_products_ids | | —————————————— | 1

  • 0

I have this table,

--------------------------------------------
|   products_id   |   related_products_ids |
| ------------------------------------------
|    1            |   2                    |
|    1            |   3                    |
|    1            |   4                    |
--------------------------------------------

Problem 1

I have these checkboxes,

<input value="1" type="checkbox" name="rp_product[]" id="in-category1"> Microsoft IntelliMouse Pro 1
<input value="2" type="checkbox" name="rp_product[]" id="in-category2"> Microsoft IntelliMouse Pro 2
<input value="3" type="checkbox" name="rp_product[]" id="in-category3"> Microsoft IntelliMouse Pro 3
<input value="3" type="checkbox" name="rp_product[]" id="in-category3"> Microsoft IntelliMouse Pro 4

I used this code,

<?php
echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">';
global $wpdb;
$sql = "SELECT related_products_ids FROM ".TABLE_RELATED_PRODUCTS." where products_id = '" . (int)$HTTP_GET_VARS['pID']."'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$rp_sql = "select products_id, products_name from ".TABLE_PRODUCTS_DESCRIPTION." where products_id !='" . (int)$HTTP_GET_VARS['pID']."' order by products_name";
$rp_1 = mysql_query($rp_sql);
while($rp_2 = mysql_fetch_array($rp_1)) {
    $checked = '';
    if ($row['related_products_ids'] == $rp_2['products_id']) $checked = " checked";
    echo "<li id=\"category-".$rp_2['products_id']."\" class=\"popular-category\"><label class=\"selectit\"><input value=\"".$rp_2['products_id']."\" type=\"checkbox\" name=\"rp_product[]\" class=\"rp_item\"" . $checked . "> <span>".$rp_2['products_name']."</span></label></li>";
}
mysql_free_result($rp_1);
echo '</ul></div></div>';
?>

But my php code is not working, only 1 checkbox is checked. How can i make those checkboxes checked if their value exist on the database table?

Problem 2

I also wanted to output the related products by products ids,

I used this code,

$sql = "SELECT related_products_ids FROM ".TABLE_RELATED_PRODUCTS." where products_id = '" . (int)$_GET["products_id"]."'";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result); 
$lst_rp = explode(',', $row['related_products_ids']);
if(mysql_num_rows(mysql_query($sql))){
echo '<ul id="related-products-array">';
foreach($lst_rp as $rp_id) {
    $res = "select p.products_id, products_type, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . $rp_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'";
    $result1 = mysql_query($res);
    $row1 = mysql_fetch_array($result1);
     if(mysql_num_rows(mysql_query($res))){
       if ($nw_price = tep_get_products_special_price($rp_id)) {
        $products_price1 = '<del>' . $currencies->display_price($row1['products_price'], tep_get_tax_rate($row1['products_tax_class_id'])) . '</del><br><span class="productSpecialPrice">' . $currencies->display_price($nw_price, tep_get_tax_rate($row1['products_tax_class_id'])) . '</span>';
       } else {
        $products_price1 = $currencies->display_price($row1['products_price'], tep_get_tax_rate($row1['products_tax_class_id']));
       }
        echo '<li><a href="'.get_permalink($storepage).'?slug=product_info.php&products_id='.$rp_id.'" target="_blank">'.tep_image(DIR_WS_IMAGES . $row1['products_image'], addslashes($row1['products_name']), null, null, 'hspace="5" vspace="5" height="120" width="120"').'<br>'.$row1['products_name'].'</a><br>'.$products_price1.'</li>';
     } else {
     }

}
echo '</ul>';
} else {
echo 'No related products.';
}
echo '<div style="clear:both;"></div>';

Only one related product is displayed. I know there is something wrong with my code, I just can’t figure it out.

Please Help.

  • 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-01T23:27:16+00:00Added an answer on June 1, 2026 at 11:27 pm

    The easiest way would be to do this:

    function isChecked() {
        # perform SQL query
        # if value exists, set $exists to true
        if ($exists) {
            return "checked";
        } else {
            return "";
        }
    }
    
    <input type="checkbox" <?php echo isChecked() ?> />
    

    Obviously, you would need to adjust your code, maybe put the whole input tag in a loop in php and write ‘checked’ or not depending on your query. But the key is:

    <input type="checkbox" checked /> Checked by default
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this table where I can generate dynamic rows (which has input <type=text
I have this table Id PId Name Value ------------------------ 1 null foo null 2
I have this table: <table id="tblId"> <thead> <tr> <th>View Name</th> <th>View Description</th> </tr> </thead>
I have this table named sample with these values in MS Sql Server: ID
I have this table where you add taxes. |Name | Rate | Description |
I have this table ATTRIBUTE id name um 12 capacity MB;GB;TB And this table2
I have this table UMS id_attribute value order 1 MB 1 1 Gb 2
I have this table: create table demo ( key number(10) not null, type varchar2(3)
I have this table ID Level Value 1 1 10 1 2 20 1
I have this table in my DB: Group - ID-Name - 1 -abc -

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.