baby machinery baby machinery - 1 year ago 67
MySQL Question

Retrieve and Count Tags in db phalcon

I have blog table in my db, and in tags field tags are inserted like "php,java,mysql,asp" i mean each post have comma separated multiple tags. i want retrieve all tags individually and also i want to count how many post have in each tags.

I am using phalcon 3.0 with php 7.


$bloger = Blogs::find();
foreach($bloger as $b)

$tager = Tags::find(["order" => "tagname ASC"]);
foreach($tager as $t)

1# It's render like "Education,Law,Property,Rights,Social" how to explode each tags from each post in blogs table.

2# It's render like "Education" "Law" "Property" "Rights" "Social" in tags table.

3# want to loop through query like :

$qry = $this->modelsManager->executeQuery("SELECT Blogs.tags FROM Blogs WHERE Blogs.tags = Education");

4# and the count how many post have related with each tag.

Is there any simple easy query? please give a working example.

Answer Source

Just paste this line in your volt.


<?php $count = Blogs::find(["tags LIKE :title:","bind"=>["title"=>'%'.$tags->tagname.'%']]); echo(count($count)); ?>