简体   繁体   中英

Use GROUP_CONTACT result as normal php code or string

I am not sure if this is working. Im trying to use the result from concat as normal php code. But I am getting plain text result. This is my code:
Query 1:

$resultdc = $wpdb->get_row($wpdb->prepare("SELECT user_id, goals_date, YEAR(goals_date) AS yearof, DATE_SUB(DATE(goals_date), INTERVAL DAYOFWEEK(goals_date) -1 DAY) AS weekof, TIME_FORMAT(SEC_TO_TIME(SUM(TIME_TO_SEC(end_time))-SUM(TIME_TO_SEC(start_time))), '%H:%i') AS st_time, SUM(TIME_TO_SEC(end_time)-TIME_TO_SEC(start_time)) AS ltime, $sumleads $sumgoals FROM $table WHERE user_id IN($members) AND DATE_SUB(DATE(goals_date), INTERVAL DAYOFWEEK(goals_date) -1 DAY) = DATE_SUB(DATE('$goals_date'), INTERVAL DAYOFWEEK('$goals_date') -1 DAY) GROUP BY weekof"));

Query 2:

$dcharts = $wpdb->get_row($wpdb->prepare("SELECT GROUP_CONCAT('[\"',goalname,' - \'.\$resultdc->LT',goal_id,'.\'\", \'.\$resultdc->LT',goal_id,'.\']') AS dchart FROM wpgetyp_ppi_goalsettings WHERE user_id = '$head' AND goaltype ='leadtype' GROUP BY user_id"));

Result:

["Expired - '.$resultdc->LT1.'", '.$resultdc->LT1.'],["FSBOs - '.$resultdc->LT2.'", '.$resultdc->LT2.'],["Buyers - '.$resultdc->LT3.'", '.$resultdc->LT3.'],["Agent - '.$resultdc->LT4.'", '.$resultdc->LT4.'],["Followup - '.$resultdc->LT5.'", '.$resultdc->LT5.'],["Circle Marketing - '.$resultdc->LT6.'", '.$resultdc->LT6.'],["Door Knocking - '.$resultdc->LT21.'", '.$resultdc->LT21.']

I want to display result of $resultdc->* from first query. Or any better idea. Thank you so much.

The fact that there are dollar-signs in your results means that your quoting is not right. Try using:

"SELECT GROUP_CONCAT(
          '[',
          goalname,
          ' - {$resultdc->LT}', 
          goal_id,
          '{$resultdc->LT}',
          goal_id,']') AS dchart 
FROM      wpgetyp_ppi_goalsettings 
WHERE     user_id = '{$head}' 
      AND goaltype ='leadtype' 
GROUP BY  user_id"

as sql-statement

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM