I am a newbie to Wordpress and php. I have a table in my database which keeps on getting updated by the users. I just wanted to write a code which gets the information from the table and display some of the information from the table in one of my page. For that purpose, I am using the following code.


$number_rows= $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->daviddgl_wp1.SaveContactForm7_7" );
while ($x<$number_rows) {
$results = $wpdb->get_results("SELECT ticket, name,email FROM $wpdb->daviddgl_wp1.SaveContactForm7_7 WHERE id = $x"
echo $results;


It gives me the following error.

Parse error: syntax error, unexpected 'echo' (T_ECHO) in /home/daviddgl/public_html/wp-content/themes/panoramic-child/cleanphppage.php on line 38

which I was not able to figure it out.

How to correct this??

Kindly note that, in future I may style the output, that is I may want to use css to style the table which I am creating using the while loop.

Thank you for helping!!!


1 Answer 1


So in this case, the problem is that your line right before the echo call is incomplete:

$number_rows= $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->daviddgl_wp1.SaveContactForm7_7" );
while ($x<$number_rows) {
    $results = $wpdb->get_results("SELECT ticket, name,email FROM $wpdb->daviddgl_wp1.SaveContactForm7_7 WHERE id = $x");

(You're missing the closing bracket and semi-column)

Note also that your echo will not work here, since $results will be an array. You'll probably want to use var_dump or print_r - like I did in the above example.

Hope this helps!

Your Answer

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

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