Title: SQL query in pages
Last modified: August 19, 2016

---

# SQL query in pages

 *  [kenrohde](https://wordpress.org/support/users/kenrohde/)
 * (@kenrohde)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/sql-query-in-pages/)
 * Hi,
 * I am new to wordpress and would like help to get the following scenario to work.
 * I have a registration page with a registration form for an event. The results
   are stored in a table on the same DB as the WP installation. I would like to 
   have the results of an SQL query display on a page of “Confirmed Attendees” where
   that SQL queries my table and spits out those results where I have flagged those
   folks who have paid the attendance fee. I then want these results to appear in
   a table with the first name, last name and attendance status.
 * My question is:
    1. How do I use the connection to the SQL DB that wordpress is already using?
    2. How do I write the PHP so that the table will have as many rows as the SQL statement
       will spit out?
 * Your help is very much appreciated.
 * Thanks
 * Kenneth

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [ryans149](https://wordpress.org/support/users/ryans149/)
 * (@ryans149)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/sql-query-in-pages/#post-1139657)
 * You can simply use thewp-config.php file using require once.
 * Or you can use the same database using the mysql connection string..
 *  Thread Starter [kenrohde](https://wordpress.org/support/users/kenrohde/)
 * (@kenrohde)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/sql-query-in-pages/#post-1139667)
 * OK – here’s what I have so far but it’s obviously not working. However, it may
   give you a good idea what I am trying to do. I am using this code as part of 
   a page.php within my theme folder. My idea is to then simply make the page use
   this template and the results should show…
 *     ```
       <?php
       /*
       Template Name: Page Show Youth Attendee Status
       */
       ?>
       <?php get_header(); ?>
       <div id="content">
       	<div id="contentleft">
       		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       		<h1><?php the_title(); ?></h1>
       		<?php the_content(__('Read more'));?><div style="clear:both;"></div>
   
       		<!-- SQL Spits out results here  -->
       		WP_Query($query = 'select first_name, last_name, reg_confirm, count(1) as count_rows from ft_form_1')
       		<!-- table here  -->
       		echo "<table border=\"1\" align=\"center\">";
       		echo "<tr><th>First Name</th>";
       		echo "<th>Last Name</th></tr>";
       		echo "<th>Registration Status</th></tr>";
       		while ( $counter <= sum(count_rows_SQL) ) {
       		echo "<tr><td>";
       		echo $first_name_SQL;
       		echo "</td><td>";
       		echo $last_name_SQL;
       		echo "</td></tr>";
       		echo $reg_confirm_SQL;
       		echo "</td></tr>";
       		$counter = $counter + 1;
       		}
       		echo "</table>";
   
       		<!-- END OF SQL Spits out results here  -->
   
       		<!--
       		<?php trackback_rdf(); ?>
       		-->
       		<?php endwhile; else: ?>
       		<p><?php _e('Sorry, no posts matched your criteria.'); ?></p><?php endif; ?>
   
       	</div>
   
       </div>
   
       <!-- The main column ends  -->
   
       <?php get_footer(); ?>
       ```
   
 * Any helps is appreciated.
 * Thanks a lot!!!!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘SQL query in pages’ is closed to new replies.

## Tags

 * [pages](https://wordpress.org/support/topic-tag/pages/)
 * [query](https://wordpress.org/support/topic-tag/query/)
 * [sql](https://wordpress.org/support/topic-tag/sql/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [kenrohde](https://wordpress.org/support/users/kenrohde/)
 * Last activity: [16 years, 10 months ago](https://wordpress.org/support/topic/sql-query-in-pages/#post-1139667)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
