Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Pull down default text


mjaegare

Recommended Posts

Posted

Hi.

I have tree pull downs containing products. I need each pull down to have the default text ("Choose") on top with default value 0.

How can i do this?

 

The array code:

 

$tq = tep_db_query("select product_1_id from " . TABLE_2GETHER . " where status = 1 and discount > 0 order by " .$together_savings. " ''");

 if ( ($action == 'new') || ($action == 'edit') ) {
$form_action = 'insert';
if ( ($action == 'edit') && isset($HTTP_GET_VARS['tID']) ) {
  $form_action = 'update';
  $together_query = tep_db_query("select tid,
							product_1_id as product1_id, 
							product_2_id as product2_id,
	product_3_id as product3_id, 
							discount, 
							type, 
							status 
					 from " . TABLE_2GETHER . "
					 where tid = '" . (int)$HTTP_GET_VARS['tID'] . "' order by product1_id");

  $together = tep_db_fetch_array($together_query);

  $tInfo = new objectInfo($together);
} else {
  $tInfo = new objectInfo(array());

  $excludes_array1 = array();
  $excludes_array2 = array();
  $excludes_array3 = array();

  $excludes_array = array_merge($excludes_array1,$excludes_array2,$excludes_array3);
}

 

 

The display code:

 

<?php echo (isset($tInfo->product1_id)) ? $tInfo->product1_id : tep_draw_products_pull_down('product1_id', 'style="font-size:10px"', $excludes_array); ?>
<?php echo (isset($tInfo->product2_id)) ? $tInfo->product2_id : tep_draw_products_pull_down('product2_id', 'style="font-size:10px"', $excludes_array); ?>
<?php echo (isset($tInfo->product3_id)) ? $tInfo->product3_id : tep_draw_products_pull_down('product3_id', 'style="font-size:10px"', $excludes_array); ?>

 

 

Regards

 

Magnus J

Posted

Oh, i forgot.

Here is the function from general.php:

 

function tep_draw_products_pull_down($name, $parameters = '', $exclude = '') {
global $currencies, $languages_id;

if ($exclude == '') {
  $exclude = array();
}

$select_string = '<select name="' . $name . '"';

if ($parameters) {
  $select_string .= ' ' . $parameters;
}

$select_string .= '>';

$products_query = tep_db_query("select p.products_id, pd.products_name, p.products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by products_name");
while ($products = tep_db_fetch_array($products_query)) {
  if (!in_array($products['products_id'], $exclude)) {
	$select_string .= '<option value="' . $products['products_id'] . '">' . $products['products_name'] . ' (' . $currencies->format($products['products_price']) . ')</option>';
  }
}

$select_string .= '</select>';

return $select_string;
 }

Posted

You would do better using the built in function, so:

 

$products_array = array();
$products_array[0] = array('id' => '0', 'text' => 'Choose');
$products_query = tep_db_query("select p.products_id, pd.products_name, p.products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by products_name");
while ($products = tep_db_fetch_array($products_query)) {
  if (!in_array($products['products_id'], $exclude)) {

$products_array[] = array('id' => $products['products_id'], 'text' => $products['products_name']);

  }
}

 

builds your array, then just put:

 

return tep_draw_pull_down_menu($name, $products_array, '', $parameters);

 

to end your function

 

:)

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Posted

Hey Sam, thank for your help!

 

I tried your suggestion but I get the following error:

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/MYSITE/public_html/admin/2gether.php on line 79

 

Line 79 is:

if (!in_array($products['products_id'], $exclude)) {

Posted

Do you still have the

 

if ($exclude == '') {

$exclude = array();

}

 

in the function, I did'nt look @ what you're doing with that, I only showed creating the drop

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Posted

I´m sorry to say... I´m totally lost.

I have a fever and I´m tired and can´t think staight. <_<

Still this needs to get fixed a.s.a.p.

 

I have the stuff I told you about in the beginning of this thread.

If you can, please tell me where to put what. Like I´m a ten-year-old (wich is somewhat correct regarding my coding skills :-))

 

Thanks...

Posted

Looking at what you've given $exclude is always empty, so just remove the line, ie instead of

 

if (!in_array($products['products_id'], $exclude)) {

$products_array[] = array('id' => $products['products_id'], 'text' => $products['products_name']);

  }

 

put

 

$products_array[] = array('id' => $products['products_id'], 'text' => $products['products_name']);

Sam

 

Remember, What you think I ment may not be what I thought I ment when I said it.

 

Contributions:

 

Auto Backup your Database, Easy way

 

Multi Images with Fancy Pop-ups, Easy way

 

Products in columns with multi buy etc etc

 

Disable any Category or Product, Easy way

 

Secure & Improve your account pages et al.

Posted

Ok, so...

 

The $exclude array in full is actually this (with lines commented out):

// UNCOMMENT TO USE PRODUCTS ONLY ONCE
  $excludes_array1 = array();
  // $exclude_query1 = tep_db_query("select product_1_id from " . TABLE_2GETHER);
  // while ($excludes1 = tep_db_fetch_array($exclude_query1)) {
  //   $excludes_array1[] = $excludes1['product_1_id'];
  // }
  $excludes_array2 = array();
  // $exclude_query2 = tep_db_query("select product_2_id from " . TABLE_2GETHER);
  // while ($excludes2 = tep_db_fetch_array($exclude_query2)) {
  //   $excludes_array2[] = $excludes2['product_2_id'];
  // }
  $excludes_array3 = array();
  // $exclude_query3 = tep_db_query("select product_3_id from " . TABLE_2GETHER);
  // while ($excludes3 = tep_db_fetch_array($exclude_query3)) {
  //   $excludes_array3[] = $excludes3['product_3_id'];
  // }

  $excludes_array = array_merge($excludes_array1,$excludes_array2,$excludes_array3);
}

 

I might want to uncomment those lines in the future so... here is what I have done.

 

I created a new function like this:

function tep_draw_products_pull_down2($name, $parameters = '', $exclude = '') {
global $currencies, $languages_id;

if ($exclude == '') {
  $exclude = array();
}

$products_array = array();
$products_array[0] = array('id' => '0', 'text' => 'Choose');
$products_query = tep_db_query("select p.products_id, pd.products_name, p.products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by products_name");
while ($products = tep_db_fetch_array($products_query)) {
  if (!in_array($products['products_id'], $exclude)) {

$products_array[] = array('id' => $products['products_id'], 'text' => $products['products_name']);

  }
}

return tep_draw_pull_down_menu($name, $products_array, '', $parameters);
 }

 

Or, if I´m not using the exclude I guess I could do this?:

function tep_draw_products_pull_down2($name, $parameters = '', $exclude = '') {
global $currencies, $languages_id;

$products_array = array();
$products_array[0] = array('id' => '0', 'text' => 'Choose');
$products_query = tep_db_query("select p.products_id, pd.products_name, p.products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by products_name");
while ($products = tep_db_fetch_array($products_query)) {
  $products_array[] = array('id' => $products['products_id'], 'text' => $products['products_name']);
}

return tep_draw_pull_down_menu($name, $products_array, '', $parameters);
 }

 

Does this look alright to you?

It seems to work.

Archived

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

×
×
  • Create New...