Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

get short description from databse and display


stevennickelby

Recommended Posts

Hi all,

 

I have installed the short description contibution...

 

ihave altered table (in mysql) 'products_desription' and added 'sort_desc'.

 

and on the server side altered files

'categories.php'

'general.php'

'index.php'

'advanced_search.php'

'products_new.php'

and 'product_listing.php'

 

In the admin-control panel-products, i now have a box for products where i can enter a short description...

 

My qestion is in 'new_products.php' what script do I add in order for it to show the short description?

 

I gather there must be a script to get the relevent products short desription from the database, then one to display it?

 

I'm not good with php; please can someone help? :-"

Link to comment
Share on other sites

In "new_prducts.php" i added

 

 

'short_desc' in the $new_products_query and

 

$new_products['short_desc'] = tep_get_products_name($new_products['products_id']);

 

and short_desc in a 2 other places near the end,

 

when i load the page...it displays

 

1054 - Unknown column 'short_desc' in 'field list'

 

select p.products_id, p.products_image, short_desc, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from products p left join specials s on p.products_id = s.products_id where products_status = '1' order by p.products_date_added desc limit 9

 

Below is the new_products.php script.

How do i get it, to get the data of the product from...table-products_description, field-short_desc. And display

it under product name?

I am lost and need help! :blush:

 

 

<?php

/*

$Id: new_products.php,v 1.34 2003/06/09 22:49:58 hpdl Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

?>

<!-- new_products //-->

<?php

$info_box_contents = array();

$info_box_contents[] = array('text' => sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')));

 

new contentBoxHeading($info_box_contents);

 

if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {

$new_products_query = tep_db_query("select p.products_id, p.products_image, short_desc, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);

} else {

$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . $new_products_category_id . "' and p.products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);

}

 

$row = 0;

$col = 0;

$info_box_contents = array();

while ($new_products = tep_db_fetch_array($new_products_query)) {

$new_products['products_name'] = tep_get_products_name($new_products['products_id']);

$new_products['short_desc'] = tep_get_products_name($new_products['products_id']);

$info_box_contents[$row][$col] = array('align' => 'right',

'params' => 'class="smallText" height="130" width="33%" valign="top"',

'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], $new_products['short-desc'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><td valign="top" align="left"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . $new_products['products_name'] . $new_products['short-desc'] .'</a>');

$col ++;

if ($col > 2) {

$col = 0;

$row ++;

}

}

 

new contentBox($info_box_contents);

?>

 

<!-- new_products_eof //-->

Link to comment
Share on other sites

take the short_desc reference out of the query. It is not finding it because you are querying the products table.

 

The easiest way would be either to make a helper function similar to tep_get_products_name in general.php or a direct database query on products_description.

 

If you are fairly new to all this you will find making the helper function easier.

Link to comment
Share on other sites

take the short_desc reference out of the query. It is not finding it because you are querying the products table.

 

The easiest way would be either to make a helper function similar to tep_get_products_name in general.php or a direct database query on products_description.

 

If you are fairly new to all this you will find making the helper function easier.

 

 

 

thanks for that!

 

I inserted the helper function and made some changes to look for 'short_desc'...

but the short description doesn't display.

 

If you can help once more thanks very much.

 

here's the new_products.php

 

<?php

/*

$Id: new_products.php,v 1.34 2003/06/09 22:49:58 hpdl Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

?>

<!-- new_products //-->

<?php

$info_box_contents = array();

$info_box_contents[] = array('text' => sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')));

 

new contentBoxHeading($info_box_contents);

 

if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {

$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);

} else {

$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . $new_products_category_id . "' and p.products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);

}

 

//------------helper function

 

function tep_get_short_desc($product_id, $language = '') {

global $languages_id;

 

if (empty($language)) $language = $languages_id;

 

$product_query = tep_db_query("select short_desc from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$product_id . "' and language_id = '" . (int)$language . "'");

$product = tep_db_fetch_array($product_query);

 

return $product['short_desc'];

}

 

//--------------------

 

$row = 0;

$col = 0;

$info_box_contents = array();

while ($new_products = tep_db_fetch_array($new_products_query)) {

$new_products['products_name'] = tep_get_products_name($new_products['products_id']);

$product['short_desc'] = tep_get_short_desc($product['products_id']);

$info_box_contents[$row][$col] = array('align' => 'right',

'params' => 'class="smallText" height="130" width="33%" valign="top"',

'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><td valign="top" align="left"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . $new_products['products_name'] . $product['short_desc'] .'</a>');

 

 

 

$col ++;

if ($col > 2) {

$col = 0;

$row ++;

}

}

 

new contentBox($info_box_contents);

?>

 

<!-- new_products_eof //-->

Link to comment
Share on other sites

you are confusing your variables slightly

 

$product['short_desc'] = tep_get_short_desc($product['products_id']);

 

should be

 

$new_products['short_desc'] = tep_get_short_desc($new_products['products_id']);

 

and where you try to print it change to $new_products['short_desc']

 

your helper function looks OK though - but I was expecting you to put it in general.php where it can be used throughout your code if necessary - up to you though.

Link to comment
Share on other sites

meltus if you can help again,

 

I made the changes,

 

The short descriptions don't display?

 

-how would you put it in general.php...i'm learning!

 

here it is...

 

 

 

<?php

/*

$Id: new_products.php,v 1.34 2003/06/09 22:49:58 hpdl Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

?>

<!-- new_products //-->

<?php

$info_box_contents = array();

$info_box_contents[] = array('text' => sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')));

 

new contentBoxHeading($info_box_contents);

 

if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {

$new_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);

} else {

$new_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . $new_products_category_id . "' and p.products_status = '1' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS);

}

 

//------------helper function

 

function tep_get_short_desc($product_id, $language = '') {

global $languages_id;

 

if (empty($language)) $language = $languages_id;

 

$product_query = tep_db_query("select short_desc from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . (int)$product_id . "' and language_id = '" . (int)$language . "'");

$product = tep_db_fetch_array($product_query);

 

return $new_products['short_desc'];

}

 

//--------------------

 

$row = 0;

$col = 0;

$info_box_contents = array();

while ($new_products = tep_db_fetch_array($new_products_query)) {

$new_products['products_name'] = tep_get_products_name($new_products['products_id']);

$new_products['short_desc'] = tep_get_short_desc($new_products['products_id']);

$info_box_contents[$row][$col] = array('align' => 'right',

'params' => 'class="smallText" height="130" width="33%" valign="top"',

'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $new_products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><td valign="top" align="left"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . $new_products['products_name'] . $new_products['short_desc'] . '</a>');

 

 

 

$col ++;

if ($col > 2) {

$col = 0;

$row ++;

}

}

 

new contentBox($info_box_contents);

?>

 

<!-- new_products_eof //-->

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...