Getting "Resource id #123" with php mysql query

I wrote a php/mysql query to return a table of property names. It works great as a standalone .php page, but when I include it in a wordpress template it get text saying “Resource id #123” right above the table.

I’m not sure if this is a wordpress, php or apache problem. Any help would be appreciated.

Site (see table on left): http://g2b.blakeswanson.com/ourhomes

Code:
[php] <?php
echo("











");
require("phpsqlajax_dbinfo.php"); 

// Opens a connection to a MySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {  die('Not connected : ' . mysql_error());} 

// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . mysql_error());
} 

// Select all the rows in the markers table
$query = "SELECT wp.post_title 'post_title'
  , wp.post_name 'post_name'
  ,Concat((select meta_value from wp_postmeta where post_id = wp.ID and meta_key = 'street_number'), ' '
  , (select meta_value from wp_postmeta where post_id = wp.ID and meta_key = 'route'), ' '
  , (select meta_value from wp_postmeta where post_id = wp.ID and meta_key = 'city'))  address 
  , (select meta_value from wp_postmeta where post_id = wp.ID and meta_key = 'bedrooms')  bed
  , (select meta_value from wp_postmeta where post_id = wp.ID and meta_key = 'bathrooms')  bath
  , (select meta_value from wp_postmeta where post_id = wp.ID and meta_key = 'finished_sqft')  finished_sqft
  , (select meta_value from wp_postmeta where post_id = wp.ID and meta_key = 'built_green')  built_green
  , (select meta_value from wp_postmeta where post_id = wp.ID and meta_key = 'status')  status

FROM wp_posts wp where post_type='property' 
and post_status = 'publish'
order by status asc";

$result = mysql_query($query);
if (!$result) {  
  die('Invalid query: ' . mysql_error());
} 

// Iterate through the rows, echoing into the table
while ($row = @mysql_fetch_assoc($result)){  

	// ADD ROWS TO TABLE
  echo("<tr><td style='width: 200px;'>");
	echo "<a href='ourhomes/", $row['post_name'], "'>", $row['post_title'], "</br>";
  echo$row['address'], "</a>";
	echo("</td><td style='text-align: center;'>");
  echo$row['bed'], "/", $row['bath'];  
	echo("</td><td style='text-align: center;'>");
  echo$row['finished_sqft'];  
	echo("</td><td style='text-align: center;'>");
  echo$row['built_green'];
	echo("</td><td style='text-align: center;'>");
	echo$row['status'];
	echo("</td></tr>");
} 
echo("</tbody></table>");
mysql_close($connection);
?>[/php]

Address

Bed/Bath

Finished Sqft

Built Green

Status

One more thing. Same code here, without the wordpress components.

http://g2b.blakeswanson.com/property-overview.php

Any ideas?

Wow, that was a little bit crazy. It turns out it was a wordpress/wordpress plugin problem. I took the same code I was using and put it in other template files within wordpress. That seems to have solved the problem. Must be some problem with the plugin rendering a sub php page? Who knows. Now to change my sql sub queries to joins.

Thank you all.

Sponsor our Newsletter | Privacy Policy | Terms of Service