Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

instead:

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

try:

foreach ($greeting as $greet){ $out .=  '<td>' . $greet->id . '</td>'; } 
$out .=  '</table>';  
share|improve this answer
    
Hi Michael, Thank you for the help. It works! –  Laxmidi Aug 30 '11 at 0:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.