News:

Support the VirtueMart project and become a member

Main Menu

how to insert drop down selected value into database

Started by scorp2000, January 07, 2013, 13:09:45 PM

Previous topic - Next topic

scorp2000

i have multiple drop-down boxes, all drop-downs get data from different categories. i retrieve data using select query and get id and name from categories tables.

<select name="m_id" id="m_id" onChange="showUser(this.value)">
   <option value="">Select a Motherboard:</option>

     <?php foreach ($results as $row)
     {
      echo 
'<option value="'.$row->virtuemart_product_id.'">'.$row->product_name.'</option>';

         }
?>

</select>


three drop down. motherboard contain all motherboards (total 10)

processor contain all processor

ram contain all rams

when user select motherboard uisng dropdown.. related motherboard fetch from database using ajax call which is working fine.

but when i select motherboard, processor and ram from list and then save.. id's save into database.
but all these id's drop-downs list last item(because of foreach loop).. and not the selected items.

    how i insert selected value into database

    Second after inserting correct ids how i update id when i change motherboards or processor

i am trying insert and update like this..

<select name="m_id" id="m_id" onChange="showUser(this.value)">
  <option value="">Select a Motherboard:</option>
<?php foreach ($results as $row)
{
 echo 
'<option value="'.$insert->m_id=$row->virtuemart_product_id.'">' .$row->product_name.
      
'</option>';
  
$update->m_id $row->virtuemart_product_id;

}
?>

</select>


i inserting and updating joomla's Using an Object

please give me hint.. i take too much time.. but still have no success

here is how i insert value into database

<?php
$options 
= array();

$options[] = "<option value=''>--?--</option>";

$db =& JFactory::getDBO();

$query $db->getQuery(true);

$query->select(array('a.virtuemart_product_id, a.product_name, b.virtuemart_category_id''c.published' 'c.product_sku'));

$query->from('#__virtuemart_products_en_gb AS a');

$query->join('LEFT''#__virtuemart_product_categories AS b ON (a.virtuemart_product_id = b.virtuemart_product_id)' );

$query->join('RIGHT''#__virtuemart_products AS c ON (a.virtuemart_product_id = c.virtuemart_product_id)' );

$query->where('b.virtuemart_category_id = '.$mid'AND')

      ->
where('c.published = ' .$publish );

$db->setQuery($query);

$data $db->loadObjectList();

foreach ( 
$data as $d ) {

   
$options[] = '<option value="'.$d->virtuemart_product_id.'">'.$d->product_name.'</option>';
}

?>

                 
<select class="inputbox" id="m_id" name="m_id" size="1">

<?php echo implode("\n"$options);

// insert into db
 
$profile = new stdClass();
 
 
$profile->virtuemart_product_id $this->product->virtuemart_product_id;
 
 
$profile->m_id $d->virtuemart_product_id;
 
try {

    
$result JFactory::getDbo()->insertObject('#__virtuemart_deals'$profile);

}

catch (
Exception $e) {
    
// catch any errors.
}

?>


</select>



Best Regards

Milbo

I am sorry, I do not really understand what you do and where. Should this be productdetail page? Customfields?
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

scorp2000

#2
Hi Milbo
Sorry for that

actually this is product_edit_information.php... when we add product
i am trying to add some extra drop to make a deal

these field have noting to do with vm code and calculation... and totally work independent


just want to select components from different categories and then save.

i make a table #__virtuemart_deals

virtuemart_product_id is primary key in table.. this virtuemart_product_id is product_edit_information id

now i have two drop down

motherboard
processor


both of these components access using there virtuemart_product_id

i want to save these components id's against   main virtuemart_product_id

like

virtuemart_product_id     motherboard_id   processor_id
7748                                 7756                       7766


Best Regards




[attachment cleanup by admin]