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("
Address
|
Bed/Bath
|
Finished Sqft
|
Built Green
|
Status
|
");
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]