How to retrieve db data
-
Hi I am trying to query the database and retrieve some data from my customers table. I have checked the php code on line and got no error.Here is the code can you please tell me what I am doing wrong?I am not sure I placed the hello infinity tags in the right place.
<?php /* Template Name: CustomPageT3 */ ?>
<?php get_header(); ?>
<div id=”primary” class=”content-area”>
<main id=”main” class=”site-main” role=”main”><?php
// Start the loop.
while ( have_posts() ) : the_post();// Include the page content template.
get_template_part( ‘content’, ‘page’ );// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;// End the loop.
endwhile;
?><?php
$mydb= new wpdb(‘user’,’mypassword’,’database’,’host’);
$rows = $mydb->get_results(“select columnName from customers”);
foreach ($rows as $obj) {
echo $obj->columnName;
?>
<table border=”1″>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Address</th>
</tr>
[hi_php]
global $wpdb;
$result = $wpdb->get_results ( “SELECT * FROM customers” );
foreach ( $result as $print ) {
?>
<tr>
<td><?php echo $print->name;?></td>
<td><?php echo $print->email;?></td>
<td><?php echo $print->phone;?></td>
<td><?php echo $print->address;?></td>
</tr>
<?php }
?>[/hi_php]
</main><!– .site-main –>
</div><!– .content-area –><?php get_footer(); ?>
- The topic ‘How to retrieve db data’ is closed to new replies.