I've the data structures as shown below
Array
(
[0] => Array
(
[name] => dummy0
[projects] => Array
(
[project_names] => project0
[dates] => Array
(
[0] => 5
[1] => 11
[2] => 28
)
)
)
[1] => Array
(
[name] => dummy1
[projects] => Array
(
[project_names] => project1
[dates] => Array
(
[0] => 10
[1] => 12
[2] => 28
)
)
)
)
I'ld like to get the output as following format
dummy0
Project0
5
11
28
dummy1
Project1
10
12
28
I've used below snippet but didnt get the oupput as I excepted
[replies;block=begin;sub1=projects]
[replies_sub1.val;block=tr;sub1=dates]
[replies_sub1_sub1.val;block=td]
[replies;block=end;comm=text:p]
Any kind of help will be appreciated
The problem is that your sub-data dates is actually under 2 levels of columns: projects/dates. And TBS does not support such data structure for the automatic sub-block.
The solution is to change your data structure in order to have it like this :
(
[0] => Array
(
[name] => dummy0
[dates] => Array
(
[0] => 5
[1] => 11
[2] => 28
)
....
)
....
If you cannot change the structure, you can simply use parameter ondata with a custom function that will create a new (virtual) column in your data.
PHP:
function f_ondata($BlockName,&$CurrRec,$RecNum) {
$CurrRec['dates_z'] = $CurrRec['projects']['dates'];
}
HTML:
<div style="border: solid 1px red;">
[replies;block=begin;sub1=dates_z;ondata=f_ondata]
<table border="1">
<tr>
<td>
[replies.projects.project_names]
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
[replies_sub1.val;block=tr]
</td>
</tr>
</table>
<text:p> [replies;block=end;comm=text:p] </text:p>
<div>
Related
I have two table:
1) ip status table
2) status table
In the database, status's id is the foreign key for ip status table. I want to display 'whitelist' instead of '2'
ip status table:
+==============+===============+============+
| ip_status_id | ip_address | status_id |
+==============+===============+============+
| 1 | 192.108.1.1 | 2 |
+--------------+---------------+------------+
status table:
+============+================+
| status_id | status |
+============+================+
| 1 | Blacklist |
+------------+----------------+
| 2 | Whitelist |
+------------+----------------+
and I call it through API with query like this:
$stmt = $db->prepare("SELECT * FROM tbl_ip_statuses left join
tbl_status on tbl_ip_statuses.status_id = tbl_status.status_id
WHERE tbl_ip_statuses.is_active = ?
AND tbl_ip_statuses.is_deleted = ?
group by tbl_ip_statuses.ip_status_id");
$stmt->bind_param("ii", $_GET["is_active"], $_GET["is_deleted"]);
And I do checking at controller, the data fetch exactly like I want
Here is my controller:
$listing = json_decode($ip_status);
//dd($listing);
return view('ip_status.listing')->with("ip_status", $listing);
Here is my view:
#if($ip_status)
#foreach($ip_status as $data)
<td class="uk-width-1-2">{{ $data->s_ip }}</td>
<td class="uk-width-1-2">{{ $data->s_status }}</td>
But then it show trying to get property s_ip of non object.
when I print_r($listing)
stdClass Object (
[ip_statuses] => Array (
[0] => stdClass Object (
[ip_status_id] => 1
[s_ip] => 192.108.1.1
[status_id] => 2
[is_active] => 1
[ip_status_id_create] => 0
[dt_create] => 2020-04-15 17:16:06
[ip_status_id_edit] => 0
[dt_edit] =>
[is_deleted] => 0
[ip_status_id_delete] => 0
[dt_delete] =>
[s_status] => Whitelist
[status_id_create] => 0
[status_id_edit] => 0
[status_id_delete] => 0
)
[1] => stdClass Object (
[ip_status_id] => 2
[s_ip] => 1922.131.100.1
[status_id] => 1
[is_active] => 1
[ip_status_id_create] => 0
[dt_create] => 2020-04-15 17:15:29
[ip_status_id_edit] => 0
[dt_edit] =>
[is_deleted] => 0
[ip_status_id_delete] => 0
[dt_delete] =>
[s_status] => Blacklist
[status_id_create] => 0
[status_id_edit] => 0
[status_id_delete] => 0
)
[2] => stdClass Object (
[ip_status_id] => 3
[s_ip] => 1.1.1.1
[status_id] => 2
[is_active] => 1
[ip_status_id_create] => 0
[dt_create] => 2020-04-15 17:16:06
[ip_status_id_edit] => 0
[dt_edit] =>
[is_deleted] => 0
[ip_status_id_delete] => 0
[dt_delete] =>
[s_status] => Whitelist
[status_id_create] => 0
[status_id_edit] => 0
[status_id_delete] => 0
)
)
)
ip_statuses in an array as I see from dd result,
You can access s_ip an other elements like this $listing[‘s_ip’]
Update:
Your data is reaching blade as one ‘ip_statuses’ which have array items inside, so you need to make a change in controller where you send data to view:
return view(...)->with(‘ip_status’, $listing->ip_statuses);
this problem is killing my head and I can not get a solution
Laravel version: 5.5.47
I have the most simple if statement:
#foreach($order->ship as $os)
#if($os->destination_info != 0)
{{ $os->destination_info }}
#endif
#endforeach
For some reason this does not print anything. I have tried all the options. If I just print the variable without the #if it gives me Barcelona-Spain so the the conditional is correct it should print
This is my $order->ship:
Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => stdClass Object
(
[ship_id] => 92
[order_id] => 593
[origin_id] => 11
[origin_info] => Shenzhen - China
[destination_id] => 22
[destination_info] => Barcelona - Spain
[cbm] => 3.4151
[container] => C
[container_load_date] => 1566489600
[container_arrival_date] => 1567180800
[container_number] => 10009000
[price] => 53.5
[status] => 1
[time] => 1565842730
)
[1] => stdClass Object
(
[ship_id] => 93
[order_id] => 593
[origin_id] => 15
[origin_info] => Guangzhou - China
[destination_id] => 22
[destination_info] => Barcelona - Spain
[cbm] => 4.736
[container] => C
[container_load_date] => 1566489600
[container_arrival_date] => 1566576000
[container_number] => 10009000
[price] => 52.85
[status] => 1
[time] => 1565842730
)
)
)
As per your array representation, destination_info is a string and you are comparing it as a number. you can try using isset or is_null function with a not operator. it will help you
#foreach($order->ship as $os)
#if(!is_null($os->destination_info))
{{ $os->destination_info }}
#endif
#endforeach
You can use PHP isset
#foreach($order->ship as $os)
#if(isset($os->destination_info))
{{ $os->destination_info }}
#endif
#endforeach
You can read more about isset and is_null from php official document.
I want to sort this array by product price in ascending order. How can I do this?
Array
(
[0] => stdClass Object
(
[product_id] => 16
[product_name] => Ferrari 4802
[product_details] => I know this car is good. Because I have driven this car 10 year.
[product_quantity] => 1
[product_price] => 2560
[shipping_cost] => 1000
[product_image] => ./admin_assets/image/uploads/product_image/ea28444f93d1fea413c95861bf306fbf.jpg
[product_details_image] => ./admin_assets/image/uploads/product_details/ea28444f93d1fea413c95861bf306fbf.jpg
[thumbnails_image] => ./admin_assets/image/uploads/thumbnails/ea28444f93d1fea413c95861bf306fbf.jpg
[slidder_image] => ./admin_assets/image/uploads/slidders/ea28444f93d1fea413c95861bf306fbf.jpg
[status] => 1
[slidder] =>
[category_id] => 4
)
[1] => stdClass Object
(
[product_id] => 15
[product_name] => Laborghini urus
[product_details] => I know this car is good. Because I have driven this car 10 year.
[product_quantity] => 2
[product_price] => 500
[shipping_cost] => 1000
[product_image] => ./admin_assets/image/uploads/product_image/68a7eb1c6bf5b3b43f0c3fd4ed143c68.jpg
[product_details_image] => ./admin_assets/image/uploads/product_details/68a7eb1c6bf5b3b43f0c3fd4ed143c68.jpg
[thumbnails_image] => ./admin_assets/image/uploads/thumbnails/68a7eb1c6bf5b3b43f0c3fd4ed143c68.jpg
[slidder_image] => ./admin_assets/image/uploads/slidders/68a7eb1c6bf5b3b43f0c3fd4ed143c68.jpg
[status] => 1
[slidder] =>
[category_id] => 4
)
[2] => stdClass Object
(
[product_id] => 14
[product_name] => Laborghini hurican023
[product_details] => I know this car is good. Because I have driven this car 10 year.
[product_quantity] => 4
[product_price] => 50
[shipping_cost] => 1000
[product_image] => ./admin_assets/image/uploads/product_image/65e660ef6e3ebcb0773d87c048c93e1b.png
[product_details_image] => ./admin_assets/image/uploads/product_details/65e660ef6e3ebcb0773d87c048c93e1b.png
[thumbnails_image] => ./admin_assets/image/uploads/thumbnails/65e660ef6e3ebcb0773d87c048c93e1b.png
[slidder_image] => ./admin_assets/image/uploads/slidders/65e660ef6e3ebcb0773d87c048c93e1b.png
[status] => 1
[slidder] =>
[category_id] => 4
)
)
Because the array is generated by a database query you can easily have the query do the sorting for you.
You don't show your model code but assuming you are using Query Builder (a.k.a. Active Record) you need the following in your model before you execute $this->db->get().
$this->db->order_by('product_price', 'ASC');
Here is some example code showing a full query. It assumes the table is named 'products', you want to select all the table's fields, and you want only a particular 'category_id'.
In the Model file:
public function product_by_category($category)
{
$query = $this->db
->where('category_id', $category)
->order_by('product_price', 'ASC')
->get('products');
//return all records or NULL if no records are found
return $query->num_rows() > 0 ? $query->result() : NULL;
}
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)
{
}
This is follow up of this question: count number of foreign keys
I am using doctrine 1.2 and I want to count the number of business that belongs to subcategory.
Following are the mysql tables.
1.fi_category
+----+-----------------+-----------------+
| id | name | slug |
+----+-----------------+-----------------+
2.fi_subcategory
+----+-----------------+-----------------+-------------+
| id | name | slug | category_id |
+----+-----------------+-----------------+-------------+
3.fi_business_subcategory
+----+-------------+----------------+
| id | business_id | subcategory_id |
+----+-------------+----------------+
I am using this DQL.
$q = Doctrine_Query::create()
->select('c.name, c.slug, sc.name, sc.slug')
->from('Model_Category c')
->leftJoin('c.Subcategory sc')
->leftJoin('sc.BusinessSubcategory bsc');
which gives me something like this.
Array
(
[0] => Array
(
[id] => 1
[name] => Entertainment & Lifestyle
[slug] => entertainment-lifestyle
[Subcategory] => Array
(
[0] => Array
(
[id] => 1
[name] => Arts and Crafts
[slug] => arts-and-crafts
)
[1] => Array
(
[id] => 2
[name] => Family
[slug] => family
)
[2] => Array
(
[id] => 3
[name] => Fashion
[slug] => fashion
)
)
)
)
I am looking to fetch the number of business, i.e the returned result should be something like this depending on the business it belongs.
Array
(
[0] => Array
(
[id] => 1
[name] => Entertainment & Lifestyle
[slug] => entertainment-lifestyle
[Subcategory] => Array
(
[0] => Array
(
[id] => 1
[name] => Arts and Crafts
[slug] => arts-and-crafts
[business_count] => 35
)
[1] => Array
(
[id] => 2
[name] => Family
[slug] => family
[business_count] => 10
)
[2] => Array
(
[id] => 3
[name] => Fashion
[slug] => fashion
[business_count] => 27
)
)
)
)
Tried various ways using DQL, but nothing seems to work out. Any idea how should I go with what I want?
Did you try:
$q = Doctrine_Query::create()
->select('c.name, c.slug, sc.name, sc.slug, COUNT(sc.BusinessSubcategory.id) AS business_count')
->from('Model_Category c')
->leftJoin('c.Subcategory sc')
->groupBy('c.id, sc.id');
with HYDRATE_ARRAY