I have a query that returns as a result what seems to be a BLOB
SELECT CAST(GROUP_CONCAT(CONCAT(value,'(',qty,')') SEPARATOR ', ') AS CHAR)a
FROM (
SELECT value,count(*) qty
FROM extra_field_values
WHERE fieldid = @fieldid
AND value != ''
AND itemid IN (7,8,10,12,15,16,17,18,19,20,21,22,23,24,25,26)
GROUP BY value
) x
the table is
CREATE TABLE `extra_field_values` (
`itemid` int(11) NOT NULL DEFAULT '0',
`fieldid` int(11) NOT NULL DEFAULT '0',
`value` text NOT NULL,
KEY `itemid` (`itemid`),
KEY `fieldid` (`fieldid`),
KEY `value` (`value`(1)),
KEY `inx` (`itemid`,`fieldid`,`value`(1))
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
The main idea is that i want a string per row returning value:::count separated by ###.
The problem is that php returns empty result. I have tried both mysql and mysqli as far as drivers is concerned.
Any ideas?
PHP
$result = $mysqli->query(" SELECT CAST(GROUP_CONCAT(CONCAT(value,'(',qty,')') SEPARATOR ', ') AS CHAR)a
FROM (
SELECT value,count(*) qty
FROM extra_field_values
WHERE fieldid = @fieldid
AND value != ''
AND itemid IN (7,8,10,12,15,16,17,18,19,20,21,22,23,24,25,26)
GROUP BY value
) x ") ;
while( $row = $result->fetch_assoc() ){
print_r($row);
}
Even if you execute it through phpmyadmin it returns null. Try it on EMS mysql it works like a charm.
full query
SELECT
extra_field_values.fieldid,
extra_fields.var_name,
extra_fields.field,
extra_fields.type,
@fieldid:=extra_field_values.fieldid,
(
SELECT CAST(GROUP_CONCAT(CONCAT(value,'(',qty,')') SEPARATOR ', ') AS CHAR) a
FROM ( SELECT value, @fieldid, count(*) qty FROM extra_field_values WHERE fieldid = @fieldid GROUP BY value ) x
) as v,
count(itemid) as total,
(SELECT groupid FROM extra_fields_groups_items WHERE itemid = @fieldid) as groupid
FROM extra_field_values INNER JOIN extra_fields
ON (extra_field_values.fieldid=extra_fields.fieldid)
WHERE module = 'listings'
AND itemid IN (7,8,10,12,15,16,17,18,19,20,21,22,23,24,25,26)
AND settings LIKE '%"search";s:1:"1"%'
GROUP BY fieldid
You are querying for fields matching the session variable
@fieldidbut I would guess you’re not defining that variable in your mysqli session or in your phpmyadmin environment.Or else you can use
?as a query parameter placeholder for the fieldid and bind it to a PHP variable.See http://php.net/manual/en/mysqli-stmt.bind-param.php
Does the following query do what you want, without using the @fieldid session variable?