Wednesday, 18 September 2013

PHP Unable to fetch the data from my sql Query

PHP Unable to fetch the data from my sql Query

I am trying to fetch Data from my sql Query but I am getting the wrong
data So can anyone tell me how to do it correctly.
Here Is my code
$result = mysql_query("select
CONCAT_WS(',',
(case when Q1 is not null then 'Q1' else '' end),
(case when Q2 is not null then 'Q2' else '' end),
(case when Q3 is not null then 'Q3' else '' end),
(case when Q4 is not null then 'Q4' else '' end),
(case when Q5 is not null then 'Q5' else '' end),
(case when Q6 is not null then 'Q6' else '' end),
(case when Q7 is not null then 'Q7' else '' end),
(case when Q8 is not null then 'Q8' else '' end),
(case when Q9 is not null then 'Q9' else '' end)
) as NonNullColumns
from $day
where `user` = '$user'") or die(mysql_error());
//echo $result;
if (mysql_num_rows($result) > 1) {
// looping through all results
// products node
$response["Q"] = array();
while ($row = mysql_fetch_assoc($result)) {
// temp user array
$qnumber = array();
$qns= array();
$qnumber["Q".$i] = $row["$Q"];
$i = $i + 1;
// push single product into final response array
array_push($response["Q"], $qnumber);
I am getting the following Output from my SQl query
NonNullColumns
Q1,Q2,Q3,,,,,,
Q1,Q2,Q3,,,,,,
Q1,Q2,Q3,,,,,,
Q1,Q2,Q3,,,,,,
Q1,Q2,Q3,,,,,,
Q1,Q2,Q3,,,,,,
I need to fetch the values Q1, Q2,Q3 from my SQl query output but I am
able to fetch
{"Q":[{"Q":null},{"Q1":null},{"Q2":null},{"Q3":null},{"Q4":null},{"Q5":null}],"success":1}
So Can any one tell me how to obtain the followig output
{"Q":[{Q1},{Q2},{Q3}],"success":1}

No comments:

Post a Comment