Forums

split and list the string

samir1903 11 Jan, 2019
Hello everyone
checkboxes have

photoshop=photosohop
word=word
excel=excel
powerpoint=powerpoint
other=other


this is written with db save
courses:{data.join[, ]:courses}
and output is in example of

photoshop, word, excel, powerpoint
photosohp, excel, other
excel,other
word,excel

i want to know how many excel how many word and list
for example
word 10
excel 7
other 3

so i know word is the most popular program
how can i do this?
healyhatman 11 Jan, 2019
So you have that all stored in your database and you want a read data to tell you how many of each? According to a search that's actually quite difficult to do in MYSQL. You might have to use PHP to instead loop through the results and foreach($this->get('read_data#')) add 1 to each count if strpos !== false
samir1903 12 Jan, 2019
i am sorry but i a think i a bit confused about this do you mind to be little more clear on how to do it?
healyhatman 12 Jan, 2019
$word = 0;
$excel = 0;
$other = 0;
foreach($this->get("read_data#") as $entry) {
$word += (strpos("word", $entry["read_data_model_name"]["field_containing_the_csv_list"]) === true ? 1 : 0);
etc etc
return array("word" => $word, "excel" => $excel, "other" => $other);

Then use {var:php_block_name.word} or {var:php_block_name.excel} etc etc
healyhatman 12 Jan, 2019
Also never copy+paste from the forums, it adds hidden format characters that will break your code.
This topic is locked and no more replies can be posted.