我有这张桌子,
--------------------------------------------
| products_id | related_products_ids |
| ------------------------------------------
| 1 | 2 |
| 1 | 3 |
| 1 | 4 |
--------------------------------------------
问题 1
我有这些复选框,
<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
我用这个代码,
<?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>';
?>
但是我的 php 代码不起作用,只选中了 1 个复选框。checked
如果它们的值存在于数据库表中,我如何制作这些复选框?
问题 2
我还想按产品ID输出相关产品,
我用这个代码,
$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>';
仅显示一种相关产品。我知道我的代码有问题,我就是想不通。
请帮忙。