I'm learning how to write a shortcode. I'm getting this error: Parse error: syntax error, unexpected T_FOREACH . I'm having problems with concatenating it properly.
<?php
/*
Plugin Name: My Plugin
Plugin URI:
Description: This does blah
Version: 1.0
Author URI:
*/
function csf_cap_databaseinfo() {
global $wpdb;
$greeting = $wpdb->get_results($wpdb->prepare("SELECT * FROM wp_test;"));
$out = '<table>
<tr>
<th>ID</th>
<th>Greeting</th>
</tr>';
$out .= foreach ($greeting as $greet){ .'<tr><td>' . echo $greet->id . '</td></tr>' . } .'</table>';
return $out;
}
add_shortcode('db-info', 'csf_cap_databaseinfo');
?>
Any suggestion on how to fix this error? Thank you.
-Laxmidi
I'm learning how to write a shortcode. I'm getting this error: Parse error: syntax error, unexpected T_FOREACH . I'm having problems with concatenating it properly.
<?php
/*
Plugin Name: My Plugin
Plugin URI: http://mysite
Description: This does blah
Version: 1.0
Author URI: http://www.mysite
*/
function csf_cap_databaseinfo() {
global $wpdb;
$greeting = $wpdb->get_results($wpdb->prepare("SELECT * FROM wp_test;"));
$out = '<table>
<tr>
<th>ID</th>
<th>Greeting</th>
</tr>';
$out .= foreach ($greeting as $greet){ .'<tr><td>' . echo $greet->id . '</td></tr>' . } .'</table>';
return $out;
}
add_shortcode('db-info', 'csf_cap_databaseinfo');
?>
Any suggestion on how to fix this error? Thank you.
-Laxmidi
Share Improve this question edited Aug 29, 2011 at 23:48 Laxmidi asked Aug 29, 2011 at 22:23 LaxmidiLaxmidi 9714 gold badges19 silver badges37 bronze badges1 Answer
Reset to default 1instead:
$out .= foreach ($greeting as $greet){ .'<td>' . echo $greet->id . '</td>' . } .'</table>';
try:
foreach ($greeting as $greet){ $out .= '<td>' . $greet->id . '</td>'; }
$out .= '</table>';