How to display external data in Views 3, without node, CCK and content type
I have an external database, Mydbase that contains the following tables:
- Company: maincode, subcode, company name
- Product: product code, product name
- Capacity: maincode, subcode, product code, capacity, since
I want to display in a view maincode, sub code, product code, company name, product name, capacity, and since.
I want to expose the product code filter as well.I have setup the setting.php db_url of the external database. Then, I created the form in page for selecting the company; once the user selects the company, I store the company code in a session variable 开发者_如何学Cfor reference. I will use this variable for fetching the information in a view. I will enter its value in the default argument PHP code, and Views will provide me the capacity information of selected company. This page auto redirects the user to the view page of capacity, using the drupal_goto()
function. The code of the page is attached below. I have a problem with the code: I cannot store the company name in variable; I am only able to fetch the information for "maincode" and "subcode." How do I fetch the display value of the drop down instead of the tag value?
I do not know how to use view for external database without the content type define in drupal, and do not have any cck field as well. If i can i want to expose the product code as well in the view.so user can select and view one product of select company.
if(isset($_SESSION['ses_maincode'])){
echo "Company Main code Selected = " . $_SESSION['ses_maincode'] . "<br/>";
echo "Company Sub code Selected = " . $_SESSION['ses_subcode'] . "<br/>";
echo "<br />";
}
$output .= drupal_get_form('formexample_testform');
echo $output;
function formexample_testform() {
$myvalue = array();
$count = 0;
db_set_active('mydb');
$result = db_query('SELECT maincode,subcode,cname FROM {company}');
while ($row = db_fetch_array($result)) {
$arrayvalue = $row[maincode] . '+' . $row[subcode];
$myvalue[$arrayvalue]=$row['cname'];
$count = $count + 1;
}
db_set_active('default');
$form['select_company'] = array(
'#title' => t('Select Company'),
'#type' => 'select',
'#description' => t('Pick the company '),
'#options' => $myvalue,
'#multiple' => FALSE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit')
);
return $form;
}
function formexample_testform_submit($form_id, $form_state) {
$name = $form_state['values']['select_company'];
drupal_set_message(t(' You have select the company %name', array('%name' => $name)));
$mystring = $form_state['values']['select_company'];
$pos = strrpos($mystring, "+");
$endpoint = strlen($mystring) - $pos;
$_SESSION['ses_maincode']=substr($mystring,0,$pos);
$_SESSION['ses_subcode']=substr($mystring,$pos+1,$endpoint);
$urlstring='node/7';
/** . $_SESSION['ses_maincode']; */
drupal_goto($urlstring);
}
精彩评论