0

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.com
Description: This does blah
Version: 1.0
Author URI: http://www.mysite.com
*/




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

1 Answer 1

1

instead:

$out .=  foreach ($greeting as $greet){ .'<td>' . echo $greet->id . '</td>' . } .'</table>';

try:

foreach ($greeting as $greet){ $out .=  '<td>' . $greet->id . '</td>'; } 
$out .=  '</table>';  
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.