我在产品页面上有一个PHP脚本,用于显示用户在框中显示的最近5个已查看产品,以及同一产品页面上的PHP脚本,该脚本显示了与名称相似的所有类别中的10个随机产品主要产品。
我想要做的是根据最近查看的产品而不是产品标题名称提供随机产品,并且仅限于他们正在查看的产品的父类别子类别内的所有产品。
以下是上次查看过的产品代码http://pastebin.com/3LrLKHFT,以下是随机商品代码http://pastebin.com/16zy411R
任何人都可以帮助我实现这个目标吗?
最近浏览:
<?php
define('MAX_COLS_FOOTER', 1);
define('MAX_ROWS_FOOTER', 4);
if (strlen($recently_viewed_footer>1)) {
$info_box_contents = array();
$info_box_contents[] = array('align' => 'left',
'text' => 'RECENTLY VIEWED'
);
new infoBoxHeading($info_box_contents, false, false);
$counter = 0;
$info_box_contents = array();
$recent_products = split(';',$recently_viewed_footer);
$rows=0;
$cols=0;
foreach ($recent_products as $recent) { if ((strlen($recent) >0) && ($counter < (MAX_ROWS_FOOTER*MAX_COLS_FOOTER)) && ($rows<MAX_ROWS_FOOTER)) {
$recent_info = tep_db_query("select p.products_image from " . TABLE_PRODUCTS . " p where p.products_id = '" . $recent. "'");
$recent_info_values = tep_db_fetch_array($recent_info);
$counter++;
if (strlen($counter) < 2) {
$counter = '0' . $counter;
}
$info_box_contents[$rows][$cols] = array('align' => 'left',
'params' =>'',
'text' => '
<!-- Begin Wrapper -->
<div id="wrapperrightinnner">
<!-- Begin Left Column -->
<div id="leftcolumnrightinnner">
<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $recent, 'NONSSL') . '">' . tep_image(DIR_WS_IMAGES . $recent_info_values['products_image'], tep_get_products_name($recent), '60px', '55px') . '
</div>
<!-- End Left Column -->
<!-- Begin Right Column -->
<div id="rightcolumnrightinnner">
' . tep_get_products_name($recent) . '</div></a>
<!-- End Right Column -->
</div>
<!-- End Wrapper -->
'
);
$cols++;
if ($cols >= MAX_COLS) {
$cols = 0;
$rows++;
}
}
} new tableBox($info_box_contents,true);
}?>
随机产品:
<?php
$i=0;
$pieces = explode(" ", $products_name);
$productname=$pieces[1]." ".$pieces[2];
$productname1="%".$productname."%";
$productname2="%".$pieces[1]."%";
$productname3="%".$pieces[0]."%";
$query="select * from products_description where products_name LIKE '$productname3' OR '$productname1' OR '$products_name' limit 0,$popular_at_shop";
//$query="select * from products_description where products_name like '$productname1' or '$productname2' or '$productname3' limit 0,$popular_at_shop";
$qry=mysql_query($query);
$qry1=mysql_num_rows($qry);
if($qry1>0)
{
?>
<?php
while($result=mysql_fetch_array($qry))
{
if($i==0 || $i%3==0)
{
echo '<tr valign="top">';
}
echo '<td align="center" width="300px;" style="padding-left:20px; padding-top:10px; padding-bottom:10px;">';
?>
<a href="<?php echo tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $result['products_id']); ?>"><div class="popularatshop"><?php echo substr($result['products_name'],0,28); ?>...</div></a>
<?php
if (($i+1)%3==0)
{
echo '</td></tr>';
}
$i++;
}
}
echo '</table></td></tr><tr>';
?></div>
<div>
</div>
<!-- End Wrapper -->
<?php
if (isset($HTTP_GET_VARS['products_id'])) {
$i=0;
$id=$HTTP_GET_VARS['products_id'];
/*
$orders_query = mysql_query("select p.products_id, p.products_image from orders_products opa, orders_products opb, orders o, products p where opa.products_id = '$id' and opa.orders_id = opb.orders_id and opb.products_id != '$id' and opb.products_id = p.products_id and opb.orders_id = o.orders_id and p.products_status = '1' group by p.products_id order by o.date_purchased desc limit 0,$also_purchase_limit");
*/
$orders_query = mysql_query("select p.products_id, p.products_image from products p, categories c, products_to_categories ptc where p.products_id = ptc.products_id and c.categories_id = ptc.categories_id and c.categories_id in (select categories_id from products_to_categories where products_id = '$id') order by rand() limit 0, 21");
$also1=mysql_num_rows($orders_query);
if($also1>0)
{
?>