Codeigniter Calendar : Adding Specific Data to A Cell - codeigniter

Here is my problem,
I need to show all the people with birthdays with the selected month, I already got on how to put the data on the specific, table cells, the only problem is that the data is also appearing on other tables cells which it is not intended. On the figure below Ori Hendricks must only be on 2 but it appears on other cells.
Here is the data for the calendar
Array
(
[2] => Array
(
[0] => Nomlanga Bentley**81
[1] => Ori Hendricks**325
)
[5] => Array
(
[0] => Rina Nash**161
)
[10] => Array
(
[0] => Gary Mullins**252
)
[12] => Array
(
[0] => Nissim Donovan**207
)
[13] => Array
(
[0] => Harper Trevino**380
)
[14] => Array
(
[0] => Sacha Arnold**167
[1] => Wade Hughes**322
[2] => Brennan Long**3
)
[15] => Array
(
[0] => Gary Hart**290
)
[21] => Array
(
[0] => Alisa Bowman**201
)
[22] => Array
(
[0] => Dustin Meyers**330
)
[26] => Array
(
[0] => Ifeoma Swanson**331
)
[28] => Array
(
[0] => McKenzie Norton**327
[1] => Asher Rasmussen**47
)
[29] => Array
(
[0] => Branden Conway**7
[1] => Luke Sullivan**176
)
[30] => Array
(
[0] => Slade Moon**16
)
)
Iv'e created a MY_calendar class and created my own generator,here is the relevant code for showing the data on the cells
if (isset($data[$day]))
{
// Cells with content
$temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_content_today'] : $this->temp['cal_cell_content'];
if(is_array($data[$day]))
{
foreach($data[$day] as $k => $v)
{
$name = substr($v,0,strpos($v,'**'));
$student_enrollment_id = substr($v,strpos($v,'**')+2);
$data_formatted[$k] = ''.trim($name).'';
}
$data_from_array = implode('',$data_formatted);
$out .= str_replace('{day}', $day, str_replace('{content}', $data_from_array, $temp));
}else{
$out .= str_replace('{day}', $day, str_replace('{content}', $data[$day], $temp));
}
}
else
{
// Cells with no content
$temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_no_content_today'] : $this->temp['cal_cell_no_content'];
$out .= str_replace('{day}', $day, $temp);
}
i don't have any other idea how to do this, please help.

The issue is happening because the array indexes are still holding the values from the last loop.
Just make this slight change in MY_calendar class code snippet you have pasted above:
<?php
if (isset($data[$day]))
{
// Cells with content
$temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_content_today'] : $this->temp['cal_cell_content'];
if(is_array($data[$day]))
{
foreach($data[$day] as $k => $v)
{
$name = substr($v,0,strpos($v,'**'));
$student_enrollment_id = substr($v,strpos($v,'**')+2);
$data_formatted[$k] = ''.trim($name).'';
}
$data_from_array = implode('',$data_formatted);
$out .= str_replace('{day}', $day, str_replace('{content}', $data_from_array, $temp));
$data_formatted = array_fill(0,count($data_formatted), null); // line added to reset the values in previous loop
}else{
$out .= str_replace('{day}', $day, str_replace('{content}', $data[$day], $temp));
}
}
else
{
// Cells with no content
$temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_no_content_today'] : $this->temp['cal_cell_no_content'];
$out .= str_replace('{day}', $day, $temp);
}
This should fix the issue.

Related

Echo from foreach

i have model that return
return array(
'senin'=> $senin->result(),
'selasa'=> $selasa->result(),
'rabu'=> $rabu->result()
);
and controller
$data['ot'] = $this->genbamodel->getOt();
in my view, i use 'foreach $ot as key' and when i tried to print_r($key) the result like this
Array()
Array ( [0] => stdClass Object ( [id_genba] => 1 [hari] => Tuesday [shift1] => 2 [shift2] => 0 ))
Array ( [0] => stdClass Object ( [id_genba] => 1 [hari] => Wednesday [shift1] => 1 [shift2] => 2 ))
how to get just shift1 = 2 and shift2 = 0 (from second array / hari=>Tuesday ??
Thankyou
I don't think you need the foreach loop to access those values. To get just the second record, you can do the below.
$ot['selasa'][0]->shift1
$ot['selasa'][0]->shift2
$ot['selasa'][0]->hari

how to make multi dimension array from sql return rows in codeigniter

how to make multi dimension array from sql return rows in codeigniter.
return values from model holding all values in $res.
$res = $this->user_model->get_room_book_join(['rooms.hotel_id' => 1]);
if ($res) {
echo '<pre>';
print_r($res);
}
I getting this type of array.this type can not helping me.
Array( [0] => Array
(
[room_id] => 1
[room_no] => 101
[room_desc] => Double Bed Deluxe Non Air Conditioned
[status] => available
[category_id] => 1
[hotel_id] => 1
[tariff_type] => normal
[room_rate] => 1000
[persons] => 0
[date_start] => 0000-00-00
[date_end] => 0000-00-00
[overview_id] => 1
[rom_id] => 1
[hot_id] => 1
[cus_id] => 2
[bok_id] => 2
[dates] => 2017-04-12
)
[1] => Array
(
[room_id] => 2
[room_no] => 101
[room_desc] => Double Bed Deluxe Non Air Conditioned
[status] => available
[category_id] => 1
[hotel_id] => 1
[tariff_type] => normal
[room_rate] => 1000
[persons] => 0
[date_start] => 0000-00-00
[date_end] => 0000-00-00
[overview_id] => 1
[rom_id] => 1
[hot_id] => 1
[cus_id] => 2
[bok_id] => 2
[dates] => 2017-04-13
)
)
Actually I want this type of array.how can i make it.please help advance thanks.
array(
[0]=>array(
[room_id]=>1
[dates]=>array(
[0]=>2014-04-12
[1]=>2014-04-13
)
)
[1]=>array(
[room_id]=>2
[dates]=>array(
[0]=>2014-04-12
[1]=>2014-04-13
)
)
)
Hi, you can try this code, this may help you
$query = $this->db->get();
$result = $query->result_array();
$main_array=array();
$actual_array=array();
foreach($result as $res){
$main_array['room_id']=$res['room_id'];
$main_array['dates']=array($res['date_start'],$res['date_end']);
$actual_array[]=$main_array;
}
//echo ""; print_r($actual_array);
return $actual_array;
try this
// after if ($res) {
for ($i=0; $i < count($res); $i++) {
$res[$i] = array(
'room_id' => $res[$i]['room_id'],
'dates' => array($res[$i]['date_start'],$res[$i]['date_end'])
);
}

Get the ordered product size and color in order items admin grid in Magento 1.9.2

I am showing a list of items ordered from all the orders from 'sales_flat_order_item table' in Magneto 1.9.2. I get the name, SKU, and all other values from the following collection.
protected function _prepareCollection() {
$collection = Mage::getModel('sales/order_item')->getCollection();
$collection->getSelect()->join(array('o' => 'sales_flat_order'), 'main_table.order_id = o.entity_id', array('increment_id','created_at'));
$this->setCollection($collection);
parent::_prepareCollection();
return $this;
}
Now I want to get the size and color of the item ordered. I am new to Magento, so I have no clue where I can get these values from.
You can access them in sales_flat_order_item table collection.
$data = $collection->getData();
$optionsData = unserialize($data['product_options']);
echo "<pre>";print_r($optionsData);
// check the [attributes_info] for the custom options
The data in product_options is serialized, so if you unserialize it you end up with something like below :
Array
(
[info_buyRequest] => Array
(
[uenc] => aHR0cDovLzUwLjU2LjIxMy4xNTcvbWVuL3RlZXMta25pdHMtYW5kLXBvbG9zL2NoZWxzZWEtdGVlLTUxNC5odG1sP29wdGlvbnM9Y2FydA,,
[product] => 409
[related_product] =>
[super_attribute] => Array
(
[92] => 20
[180] => 80
)
[qty] => 6
[return_url] =>
)
[attributes_info] => Array
(
[0] => Array
(
[label] => Color
[value] => Black
)
[1] => Array
(
[label] => Size
[value] => S
)
)
[simple_name] => Chelsea Tee
[simple_sku] => mtk004
[product_calculations] => 1
[shipment_type] => 0
[giftcard_lifetime] =>
[giftcard_is_redeemable] => 0
[giftcard_email_template] =>
[giftcard_type] =>
)

How to merge multiple arrays in PHP and output the values together?

I have a situation while developing an application on Laravel. I have three arrays in the following order. I need to merge them and display their values in the following order too. Here , it goes.
stone_name['ruby','diamond','catseye'];
stone_weight[112,223,445];
stone_rate[1000,2500,670];
I need to merge these three arrays and display the out put in this order.
stone_info = array(stone_name[0] , stone_weight[0] , stone_rate[0]);
So that the final result will be like :
stone_info = array("ruby",112,1000);
I was in the same situation and I had done it in this way. May be this can help you out.
<?php
$stone_name = ['ruby','diamond','catseye'];
$stone_weight = [112,223,445];
$stone_rate = [1000,2500,670];
$result = mergeArrays($stone_name, $stone_weight, $stone_rate);
function mergeArrays($stone_name, $stone_weight, $stone_rate) {
$result = array();
foreach ($stone_name as $key => $name ) {
$result[] = array( 'stone_name' => $name, 'stone_weight' => $stone_weight[$key], 'stone_rate' => $stone_rate[ $key ] );
}
return $result;
}
print_r($result);
Output:
Array
(
[0] => Array
(
[stone_name] => ruby
[stone_weight] => 112
[stone_rate] => 1000
)
[1] => Array
(
[stone_name] => diamond
[stone_weight] => 223
[stone_rate] => 2500
)
[2] => Array
(
[stone_name] => catseye
[stone_weight] => 445
[stone_rate] => 670
)
)
DEMO

Storing booking items information in session array of codeigniter

I wanted to store booking items such as
--> pid =1, qty=3
--> pid=5, qty=4
and so on
in codeigniter session.
I am finding it difficult and i am running out of deadline. Helping hands are very much appreciated.
I have made an example special for you. Suppouse it will helps
$data = array();
for ($i = 1; $i<=5; $i++)
{
$data[] = array('pid' => $i, 'qty' => $i);
}
$this->session->set_userdata('order_data', $data);
and output your result will be shown in session like these :
[order_data] => Array
(
[0] => Array
(
[pid] => 1
[qty] => 1
)
[1] => Array
(
[pid] => 2
[qty] => 2
)
[2] => Array
(
[pid] => 3
[qty] => 3
)
[3] => Array
(
[pid] => 4
[qty] => 4
)
[4] => Array
(
[pid] => 5
[qty] => 5
)
)
If you want to call only these data (booking data) then call
$this->session->userdata['order_data']
you can free use it in foreach for view like
foreach ($this->session->userdata['order_data'] as $key => $value)
{
}

Resources