Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

How Could I Alter This Php Script To Work?


bradbyname

Recommended Posts

hi guys. i dont know how to even start with this. prehaps you could help make this work?

 

i have a script which silverado gave me which works great to show a random product from my catalog on the front page of my phpnuke site which is as follows.

 

<?php
// Original version by [email protected]
// Version 1.2 of Randomize Everywhere by [email protected]
// I changed the script so ONLY present month items are displayed.  Also Some other minor fixes ie: product_id= not product_id/;)
//Here are the variables you must set.
$db_server = "********"; //database server
$db_user = "********"; //database user
$db_pass = "********"; //database password
$db_name = "********"; //database name
$domain_name = "********"; //don't slashes or http:
$catalog_folder_name = "********"; //no slashes
$site_title = "********"; //site name
$image_width = "100"; //how wide your images should be
$image_height = "100"; // how high your images should be
$num_products = "2"; //max number of products per page
$prod_col = "3"; //number of columns per page
$table_width = "80"; // table width in percent don't use %
$table_align = "Left"; //table alignment
$table_cspace = "1"; //table cellspacing
$table_cpadd = "1"; //table cellpadding
$product_price_show = "0"; //show prices? (1 is on, 0 is off)
$product_image_show = "1"; //show images? (1 is on, 0 is off)
$product_info_link_show = "1"; //show link to product_info.php? (1 is on, 0 is off)
$product_buy_link_show = "1"; //show link to shopping cart? (1 is on, 0 is off)
$product_name_show = "1";// show product name? (1 is on, 0 is off)
//Now upload to your website and your should be done!
//Email me at [email protected] if you have any problems.
?>
<center>
<?php

// create connection
$connection = mysql_connect("$db_server","$db_user","$db_pass")
or die("Couldn't make connection.");

// select database
$db = mysql_select_db("$db_name", $connection)
or die("Couldn't select database.");

// create SQL statement
$sql = "SELECT * FROM `products` where products_status = '1' and month(products_date_added) = month(now()) ORDER BY RAND() LIMIT 1";

// execute SQL query and get result
$sql_result = mysql_query($sql,$connection)
or die("Couldn't execute quasery.");

// format results by row
$row = mysql_fetch_array($sql_result);

$products_id = $row["products_id"];
$products_price = $row["products_price"];
$products_model = $row["products_model"];
$products_image = $row["products_image"];
//where p.products_status = '1' and month(p.products_date_added) = month(now())
$sql2 = "SELECT `products_name` FROM `products_description` WHERE products_id = '$products_id' LIMIT 1";
//$sql2 = "SELECT `products_name` FROM `products_description` WHERE products_id = '$products_id' LIMIT 1";
$sql2_result = mysql_query($sql2,$connection)
or die("Couldn't execute query.");
$row2 = mysql_fetch_array($sql2_result);

$products_name = $row2["products_name"];
$products_image_replace = str_replace("./", "/", $products_image);
$products_price_replace = str_replace("00", ".", $products_price);

if ($product_info_link_show == "1") {		
echo "<a href=\"http://$domain_name/$catalog_folder_name/product_info.php?products_id=$products_id\" target=_content style=\"text-decoration: none\">";
}
if ($product_image_show == "1") {
echo "<img src=\"http://$domain_name/$catalog_folder_name/images/$products_image_replace\" width=\"$image_width\" height=\"$image_height\" border=\"0\"><br>";
}
echo "<font face=\"Verdana, Tahoma\" size=\"-1\" color=\"#000000\">";
if ($product_name_show == "1") {
echo "$products_name";
}
if ($product_price_show == "1") {
echo "  \$$products_price_replace";
}
echo "</font>";
if ($product_info_link_show == "1") {
echo "</a>";
}
if ($product_buy_link_show == "1") {
echo "<br><a href=\"http://$domain_name/$catalog_folder_name/default.php/action/buy_now/products_id=$products_id\" target=_content><font face=\"Verdana, Tahoma\" size=\"-1\" color=\"#000000\"><b>Buy Now</b></font></a></td>";
}


// free resources and close connection
mysql_free_result($sql_result);
mysql_close($connection);
?>


</center>

 

and i have the script here from the best sellers box which is on the catalog

 

<?php
/*
 $Id: best_sellers.php,v 1.21 2003/06/09 22:07:52 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 if (isset($current_category_id) && ($current_category_id > 0)) {
$best_sellers_query = tep_db_query("select distinct p.products_id, pd.products_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and '" . (int)$current_category_id . "' in (c.categories_id, c.parent_id) order by p.products_ordered desc, pd.products_name limit " . MAX_DISPLAY_BESTSELLERS);
 } else {
$best_sellers_query = tep_db_query("select distinct p.products_id, pd.products_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_ordered desc, pd.products_name limit " . MAX_DISPLAY_BESTSELLERS);
 }

 if (tep_db_num_rows($best_sellers_query) >= MIN_DISPLAY_BESTSELLERS) {
?>
<!-- best_sellers //-->
	  <tr>
		<td>
<?php
$info_box_contents = array();
$info_box_contents[] = array('text' => BOX_HEADING_BESTSELLERS);

new infoBoxHeading($info_box_contents, false, false);

$rows = 0;
$bestsellers_list = '<table border="0" width="100%" cellspacing="0" cellpadding="1">';
while ($best_sellers = tep_db_fetch_array($best_sellers_query)) {
  $rows++;
  $bestsellers_list .= '<tr><td class="infoBoxContents" valign="top">' . tep_row_number_format($rows) . '.</td><td class="infoBoxContents"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $best_sellers['products_id']) . '">' . $best_sellers['products_name'] . '</a></td></tr>';
}
$bestsellers_list .= '</table>';

$info_box_contents = array();
$info_box_contents[] = array('text' => $bestsellers_list);

new infoBox($info_box_contents);
?>
		</td>
	  </tr>
<!-- best_sellers_eof //-->
<?php
 }
?>

 

would someone mind having a go at editing the code of the best seller, so it would work as well as the random product script at the top? just i would like to be able to show the best sellers on the front page of my site in a block. i had a go and just made a mess ( no suprise there lol .... im learning, but this is out of my depth )

Link to comment
Share on other sites

sorry :/

 

i would like to display the best sellers from my shop as a block on my phpnuke site.

 

i figured the code from the best sellers box contained within the catalog directory could be altered like the first example of code above has been

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...