undefined function db_fetch_array() - drupal-7

i received this error when i try to convert drupal 6 module to drupal 7.. i've learned that drupal 7 has a new api in database.. i'am hope someone can give a way to resolve this problem .
db_set_active('data');
$ncoa=db_fetch_array(db_query("SELECT deskripsi FROM {coa} WHERE coaid = '$baris->coa'"));
$ukpengelola=db_fetch_array(db_query("SELECT lokasi FROM {costcenter} WHERE kodecost = '$baris->kodecost'"));
$ukpengguna=db_fetch_array(db_query("SELECT lokasi FROM {costcenter} WHERE kodecost = '$baris->kodecostpemakai'"));
$zstatus=db_fetch_array(db_query("SELECT status_deskripsi AS zket FROM {pengadaan_zstatus} WHERE status_id = '$baris->status_id'"));
db_set_active('default');

db_fetch_array() is depreciated in D7, for a reference how to fix, see http://drupal.org/update/modules/6/7#dbtng
Example - Drupal 6:
<?php
$result = db_fetch_array(db_query("SELECT * FROM {boxes} WHERE bid = %d", $bid));
?>
Drupal 7:
<?php
$result = db_query("SELECT * FROM {block_custom} WHERE bid = :bid", array(':bid' => $bid))->fetchAssoc();
?>

Related

Save not working using mssql

I'm trying the following code but not working in mssql and not producing any error message in CakePHP, using version 2.6:
$product_id = $this->request->data['products']['product_id'];
$this->request->data['ProductTbl']['id'] = strtotime(date('Y-m-d H:i:s'));
$this->request->data['ProductTbl']['retailerId'] = $this->request->data['products']['retailer_id'];
$this->request->data['ProductTbl']['productCode'] = $product_id;
$this->request->data['ProductTbl']['productType'] = $this->request->data['products']['product_type'];
//$this->request->data['ProductTbl']['mmGroupId'] = $this->request->data['products']['merchandise_id'];
$this->request->data['ProductTbl']['name'] = $this->request->data['products']['product_name'];
$this->request->data['ProductTbl']['description'] = $this->request->data['products']['product_desp'];
$this->request->data['ProductTbl']['isLayawayable'] = $this->request->data['products']['product_layway'];
$this->request->data['ProductTbl']['isTaxExemptible'] = $this->request->data['products']['product_tax'];
$this->request->data['ProductTbl']['productURL'] = $this->request->data['products']['product_url'];
$this->request->data['ProductTbl']['status'] = 2;
$this->request->data['ProductTbl']['lastModified'] = date('Y-m-d H:i:s');
$this->request->data['ProductTbl']['isDeleted'] = 0;
if(!empty($this->request->data['pjosn'])){
$pjson_arr = $this->request->data['pjosn'];
$this->request->data['ProductTbl']['propertiesJson'] = json_encode($pjson_arr);
}
$this->ProductTbl->save($this->request->data['ProductTbl'],false);
$last_id = $this->ProductTbl->getLastInsertID();
Thanks.
why are u using second argument 'false' in save function ???
i thinks possible issue should be second argument. I am using cakePHP 2.7.5 and according to me your save query will be ::
$res = $this->ProductTbl->save($this->request->data);
if($res){
// do whatever you wants
}
Or the second issue may be in following code :
if(!empty($this->request->data['pjosn'])){
$pjson_arr = $this->request->data['pjosn'];
$this->request->data['ProductTbl'['propertiesJson']=json_encode($pjson_arr);
}
in json_encode your data will be in joson format ( like : {"key1":value1,"key2":value2,"key3":value3,"key4":value4,"key5":value5} ) which will not be accepted by cakePHP insert query.

Remove values after decimal in cakephp

I have the following code which gives me result: 4.00 USD
<?php echo $number->currency($auction['Product']['rrp'], $appConfigurations['currency']); ?>
I want to remove decimal. Result should be 4USD, I have tried php function round, but dosn't work. I am using cakephp framework.
Use the options
As indicated in the documentation - you can specify the decimal places to use via the options array:
places Number of decimal places to use. ie. 2
echo $number->currency(
$auction['Product']['rrp'],
$appConfigurations['currency'],
array('places' => 0)
);
Try my code also :
Rs. <?php $offerPrice = $this->Number->currency($relatedProduct['StoreProduct']['offer_price'],"") ;
echo substr($offerPrice,0, strpos($offerPrice,".")) ?>
//input = 3,175.00
//output = 3,175

Cakephp: add minutes to datetime object

I am new to cakephp and i wish to do the following:
I have a dateTime object and i want to add and subtract 30 minutes to it.
Following is my code in controller :
$time = $this->request->data['Rideoffer']['DepartureTime'];
$date = new DateTime($time['hour'] . ':' . $time['min'] . ' ' . $time['meridian']);
$currentDate = strtotime($date['date']); // this line gives error
$futureDate = $currentDate+(60*30);
$formatDate = date("Y-m-d H:i", $futureDate);
when i debug $date i get the following result:
object(DateTime) {
date => '2013-03-08 05:54:00'
timezone_type => (int) 3
timezone => 'UTC'
}
i wish to extract date from this object. How do i do so?
solved it:
$currentDate = strtotime($date->format('Y-m-d H:i:s'));
but i still dont get it that why cant i use $date['date'], i mean $date like an array.

Emails are going in spam in cake php

Here are my code:-
//Sending mail
if ($this->Session->read('Enrollment.personalinfo_language') == 'English') {
$language = "english";
$subject = "Thank you for submitting your enrollment request to Apna Energy.";
} else {
$language = "spanish";
$subject = "Gracias por enviar su solicitud de inscripci?n a Apna Energy.";
}
$details = $this->Session->read('Enrollment');
$details['plan_name'] = $product['Product']['name'];
$details['rate'] = $plan_rate;
$details['term'] = $product['Term']['term'];
$this->Email->sendAs = 'html';
$this->Email->from = 'Apna Energy <contact#apnaenergy.com>';
$this->Email->to = $this->Session->read('Enrollment.personalinfo_first_name') . ' ' . $this->Session->read('Enrollment.personalinfo_last_name') . '<' . $this->Session->read('Enrollment.personalinfo_email') . '>';
$this->Email->bcc = array('my#mail.com');
$this->Email->subject = $subject;
$this->set('details', $details);
if ($this->Session->read('Enrollment.personalinfo_language') == 'English') {
$template = "enrollment_confirmation";
} else {
$template = "enrollment_confirmation";
}
$this->Email->template = $template;
$this->Email->send();
My problem is if customer fill form they are receiving mail in his/her spam folder.. customer's mail id in "to".. and my mail id in "BCC" for me mail are coming fine in my inbox folder..
I followed two URL but they didn't work out for me..
Cakephp emails going to spam
How do you make sure email you send programmatically is not automatically marked as spam?
Guide me in right direction..
Thanks!!
by using SMTP
with normal PHP your server must be configured properly which is not easy to do as a beginner (MX records need to match the servers ip etc).
So just always stick to SMTP as mailing gateway and you will be fine.
PS: I don't think it has anything to do with your code in general, although it is not very beautiful. for instance: you should cast the array you read from the session to avoid notices thrown:
$details = (array)$this->Session->read('Enrollment');

Currency API in Drupal

I build a webshop, but the client wants a second currency, HKD. In the node-record.tpl.php file I found the line responsible for displaying the price:
print uc_currency_format($node->sell_price);
I looked into the Drupal documentation, and found the function currency_api_converter. To use it, I thought it should be like this:
print ' ('. currency_api_convert('RMB', 'EUR', $node->sell_price) .')</div>';
But for some reason, all I get is a sort of Array error:
What am I doing wrong?
Function currency_api_convert() returns array of values
$result['value'] = $value;
$result['rate'] = $rate;
$result['timestamp'] = $timestamp;
$result['date'] = $date;
$result['time'] = $time;
$result['status'] = TRUE;
$result['message'] = 'success';
Then you should to rewrite your code to
$convert = currency_api_convert('RMB', 'EUR', $node->sell_price);
print ' ('. $convert['value'] .' EUR)</div>';

Resources