Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

can someone help me with a sql query to pull product name


evanmugford

Recommended Posts

Posted

the template i installed on my store does not show the product name in the product listings, so im trying to add it

 

i came up with this line but its saying there is a sytax error

 

$productname = mysql_query('SELECT `products_name` FROM `products_description` WHERE products_id ='.$listing['products_id'].');

 

then later in the listing were i want the name displayed

'.$productname .'

 

 

erro im getting is

Parse error: parse error, unexpected T_STRING in c:\mdstoys\includes\modules\product_listing.php on line 153

 

 

 

 

 

 

 

can anyone tell me what i messed up there ?

Posted

it's:

 

$productname = mysql_query('SELECT `products_name` FROM `products_description` WHERE products_id ="'.$listing['products_id'].'"');

Posted

here is the file im editing if that helps

 

<?php
/*
 $Id: product_listing.php,v 1.44 2003/06/09 22:49:59 hpdl Exp $

E-Commerce Solutions

 Released under the GNU General Public License
*/

 $listing_split = new splitPageResults($listing_sql, MAX_DISPLAY_SEARCH_RESULTS, 'p.products_id');

 if ( ($listing_split->number_of_rows > 0) && ( (PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3') ) ) {
?>
<table border="0" width="100%" cellspacing="0" cellpadding="2">
 <tr>
<td class="smallText"><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></td>
<td class="smallText" align="right"><?php echo TEXT_RESULT_PAGE . ' ' . $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></td>
 </tr>
</table>
<?php
 }

 $list_box_contents = array();

 for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
switch ($column_list[$col]) {
  case 'PRODUCT_LIST_MODEL':
	$lc_text = TABLE_HEADING_MODEL;
	$lc_align = '';
	break;
  case 'PRODUCT_LIST_NAME':
	$lc_text = TABLE_HEADING_PRODUCTS;
	$lc_align = '';
	break;
  case 'PRODUCT_LIST_MANUFACTURER':
	$lc_text = TABLE_HEADING_MANUFACTURER;
	$lc_align = '';
	break;
  case 'PRODUCT_LIST_PRICE':
	$lc_text = TABLE_HEADING_PRICE;
	$lc_align = 'center';
	break;
  case 'PRODUCT_LIST_QUANTITY':
	$lc_text = TABLE_HEADING_QUANTITY;
	$lc_align = 'right';
	break;
  case 'PRODUCT_LIST_WEIGHT':
	$lc_text = TABLE_HEADING_WEIGHT;
	$lc_align = 'right';
	break;
  case 'PRODUCT_LIST_IMAGE':
	$lc_text = TABLE_HEADING_IMAGE;
	$lc_align = 'center';
	break;
  case 'PRODUCT_LIST_BUY_NOW':
	$lc_text = TABLE_HEADING_BUY_NOW;
	$lc_align = 'center';
	break;
}

if ( ($column_list[$col] != 'PRODUCT_LIST_BUY_NOW') && ($column_list[$col] != 'PRODUCT_LIST_IMAGE') ) {
  $lc_text = tep_create_sort_heading($HTTP_GET_VARS['sort'], $col+1, $lc_text);
}

  // $list_box_contents[0][] = array('align' => $lc_align,
				//				'params' => 'class="productListing-heading"',
			   //				 'text' => ' ' . $lc_text . ' ');
 }

 if ($listing_split->number_of_rows > 0) {
$rows = 0;
$col=0;
$listing_query = tep_db_query($listing_split->sql_query);
while ($listing = tep_db_fetch_array($listing_query)) {
 /* $rows++;

  if (($rows/2) == floor($rows/2)) {
	$list_box_contents[] = array('params' => 'class="productListing-even"');
  } else {
	$list_box_contents[] = array('params' => 'class="productListing-odd"');
  }

  $cur_row = sizeof($list_box_contents) - 1;
*/
  /*for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
	$lc_align = '';

	switch ($column_list[$col]) {
	  case 'PRODUCT_LIST_MODEL':
		$lc_align = '';
		$lc_text = ' ' . $listing['products_model'] . ' ';
		break;
	  case 'PRODUCT_LIST_NAME':
		$lc_align = '';
		if (isset($HTTP_GET_VARS['manufacturers_id'])) {
		  $lc_text = '<a class="productListing-link" href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';
		} else {
		  $lc_text = ' <a class="productListing-link" href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a> ';
		}
		break;
	  case 'PRODUCT_LIST_MANUFACTURER':
		$lc_align = '';
		$lc_text = ' <a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $listing['manufacturers_id']) . '">' . $listing['manufacturers_name'] . '</a> ';
		break;
	  case 'PRODUCT_LIST_PRICE':
		$lc_align = 'right';
		if (tep_not_null($listing['specials_new_products_price'])) {
		  $lc_text = ' <s>' .  $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</s>  <span class="productSpecialPrice">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span> ';
		} else {
		  $lc_text = ' ' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . ' ';
		}
		break;
	  case 'PRODUCT_LIST_QUANTITY':
		$lc_align = 'right';
		$lc_text = ' ' . $listing['products_quantity'] . ' ';
		break;
	  case 'PRODUCT_LIST_WEIGHT':
		$lc_align = 'right';
		$lc_text = ' ' . $listing['products_weight'] . ' ';
		break;
	  case 'PRODUCT_LIST_IMAGE':
		$lc_align = 'center';
		if (isset($HTTP_GET_VARS['manufacturers_id'])) {
		  $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';
		} else {
		  $lc_text = ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a> ';
		}
		break;
	  case 'PRODUCT_LIST_BUY_NOW':
		$lc_align = 'center';
		$lc_text = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']) . '">' . tep_image_button('button_buy_now.gif', IMAGE_BUTTON_BUY_NOW) . '</a> ';
		break;
	}

	$list_box_contents[$cur_row][] = array('align' => $lc_align,
										   'params' => 'class="productListing-data"',
										   'text'  => $lc_text);
  }*/
  $listing['products_name'] = tep_get_products_name($listing['products_id']);

$sql = 'SELECT `products_description` FROM `products_description` WHERE products_id ='.$listing['products_id'].' && language_id='.(int)$languages_id;














$productname = mysql_query('SELECT `products_name` FROM `products_description` WHERE products_id ="'.$listing['products_id'].'"'); 













$description_query = tep_db_query($sql);
$description = mysql_fetch_array($description_query, MYSQL_ASSOC);		
$description['products_description'] = substr($description['products_description'], 0, 65);
$desc_len = strlen($description['products_description']);
$description['products_description'][$desc_len-1] = '.';
$description['products_description'][$desc_len-2] = '.';
$description['products_description'][$desc_len-3] = '.';





   $list_box_contents[$rows][$col] = array('align' => 'center',
										   'params' => 'width="33%" height="200" style="padding-top:2px;"',
										   'text'  => '<div class="new_prod"><div class="image"><a href="'. tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $listing['products_id']) .'">'. tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'align="left"') . '</a></div>
									   <table border="0" cellpadding="0" cellspacing="0">
									   <tr><td valign="top" align="left"> <span class="gray" style="background-color:#E7E7E7;"><br>












'.$productname .'










  Product:   </span></td><td height="28" valign="top"><span class="special_price" style="text-decoration:none;"><br>'. $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])).'</span></td></tr><tr><td colspan="2" align="left"><br>'.$description['products_description'].'</td></tr><tr><td colspan="2">
<div class="buy" style="border-width:0px;">'.tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')).'<a class="more" href="'.tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $listing['products_id']).'">more</a> <span style="color:#E80377; font-weight:bold;">|</span> 
'. tep_draw_hidden_field('products_id', $listing['products_id']) . tep_image_submit('add.gif', IMAGE_BUTTON_IN_CART) .'</form></div></td></tr></table></div>');

 $col ++;
if ($col >2) {
  $col = 0;
  $rows ++;
}
}
  // new productListingBox($list_box_contents);
new contentBox($list_box_contents, 0);
 } else {
$list_box_contents = array();

$list_box_contents[0] = array('params' => '');
$list_box_contents[0][] = array('params' => ' style="padding:15px 0px; "',
							   'text' => '<center>'.TEXT_NO_PRODUCTS.'</center>');

new productListingBox($list_box_contents);
 }

 if ( ($listing_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3')) ) {
?>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
 <tr>
<td height="1" background="images/hpoint.gif" align="left"><img src="images/hpoint.gif" width="3" height="1" alt=""></td>
</tr>
 <tr >
<!--<td class="smallText" style="padding-top:30px;"><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></td>-->
<td class="smallText" style="padding-top:30px;" align="center"><?php echo TEXT_RESULT_PAGE . ' ' . $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></td>
 </tr>

</table>
<?php
 }
?>

Posted
thanks bro, worked, weird thoe, now its giving me a resorce id on the page instead of the products name.

osC has a function for that, see for example includes/modules/new_products.php where this is used:

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

Posted
still having no luck :( anyone have any ideas i can try?

 

Have you testes that?:

$productname = tep_get_products_name($listing['products_id']);

 

there's another possibility:

$productname_query = tep_db_query('SELECT `products_name` FROM `products_description` WHERE products_id ="'.$listing['products_id'].'"');
$productname = tep_db_fetch_array($productname_query);

Archived

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

×
×
  • Create New...