Support

Home Forums Event Espresso Premium Shortcodes | Problem to display variable on table wp_events_answer

Shortcodes | Problem to display variable on table wp_events_answer

Posted: March 18, 2014 at 8:12 pm

Viewing 2 reply threads


Hafifi Omar

March 18, 2014 at 8:12 pm

I’m trying to create shortcodes for wordpress.
I would like to display by DISTINCT from ‘answer’ but COUNT the TOTAL from ‘answer’.

If you find on foreach in my code, I have no idea how to echo the count

currently i’m using count($data->answer);

Please take a look

TABLE : wp_events_answer

??????????????????????????????????
? id ? answer ?question_id ?
??????????????????????????????????
? 1 ? Maybank ? 12 ?
? 2 ? Maybank ? 12 ?
? 3 ? Maybank ? 12 ?
? 4 ? CIMB ? 12 ?
??????????????????????????????????

My desired outcome is

??????????????????????????????????
? No ? Bank ? Total ?
??????????????????????????????????
? 1 ? Maybank ? 2 ?
? 2 ? CIMB ? 1 ?
??????????????????????????????????

My current outcome

??????????????????????????????????
? No ? Bank ? Total ?
??????????????????????????????????
? 1 ? Maybank ? 1 ?
? 2 ? Maybank ? 1 ?
? 3 ? Maybank ? 1 ?
? 4 ? CIMB ? 1 ?
??????????????????????????????????

=

$sql= ”
SELECT *, count(*)
FROM wp_events_answer
INNER JOIN wp_events_attendee ON wp_events_attendee.registration_id= wp_events_answer.registration_id
WHERE question_id=12 AND event_id=’$eventid’ GROUP by answer
“;

$datas= $wpdb->get_results($sql);
$num_rows = $wpdb->num_rows;
if ($num_rows > 0)
{
$result .= ‘<table id=”attendeeList”>
<thead>
<tr>
<th width=”10%” scope=”col”>No.</th>
<th width=”70%” scope=”col”>Group Name</th>
<th width=”20%” scope=”col”>Total</th>
</tr></thead>’;
$number = 1;

foreach ($datas as $data) {
$result .= ‘<tbody>’;
$result .= ‘<tr>’;
$result .= ‘<td>’;
$result .= $number++;
$result .= ‘</td>’;
$result .= ‘<td>’;
$result .= $data->answer;
$result .= ‘</td>’;

$result .= ‘<td>’;
$result .= count($data->answer); //i have no idea how to print total this
$result .= ‘</td>’;

$result .= ‘</tr>’;
}
$result .= ‘</table>’;

return $result;

}
else
{ return ‘There is no group’; } }


Hafifi Omar

March 18, 2014 at 8:15 pm

how to edit this post


Dean

March 19, 2014 at 5:04 am

Hi,

Large blocks of code are best linked to from a service such as Pastebin.

If you require assistance with customising the plugin, we have a list of recommended developers here – https://eventespresso.com/developers/event-espresso-pros/

Viewing 2 reply threads

The support post ‘Shortcodes | Problem to display variable on table wp_events_answer’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso