Trying to write a PHP Function to get MySQL Data
Posted: Tue Mar 09, 2010 8:29 pm
Greetings:
I'm trying to write a function to do my SQL query for me so I can call it without cluttering up my code. The problem is, it simply isn't working. Here's the code that I have:
Once I run this query, I try to do a while ($data = mysql_fetch_array($result)) { ... do stuff here ... } but the do stuff here part doesn't work!
The only thing I can think of is that it isn't finding the $dbh variable. That's included in a different file. Do I need it?
Any help from the experts would be greatly appreciated! Thank you!
I'm trying to write a function to do my SQL query for me so I can call it without cluttering up my code. The problem is, it simply isn't working. Here's the code that I have:
Code: Select all
function property_query($mls) {
$query = "SELECT
l.mls,
l.list_price,
l.listing_status,
l.street_number,
l.street_name,
l.street_type,
l.street_direction,
l.unit_number,
l.city,
l.shortzip,
l.subdivision_id,
l.furnished,
l.listing_long_description,
l.elevator,
l.year_built,
l.beds_id,
l.unit_floor,
l.total_floors,
l.full_baths,
l.half_baths,
l.sqft_living,
l.sqft_total,
l.garage_spaces,
l.carport_spaces,
l.private_pool,
l.private_spa,
l.acres,
l.waterfront_description,
l.boat_access,
l.view,
l.construction,
l.roof,
l.flooring,
l.cooling,
l.heating,
l.irrigation,
l.pets,
l.hoa_fee,
l.master_hoa_fee,
l.condo_fee,
l.broker_code,
l.office_name,
l.foreclosed,
l.shortsale,
l.broker_reciprocity,
l.lat,
l.lng,
l.num_images,
sub.id,
sub.subdivision,
sub.development,
beds.beds_id,
beds.beds_desc,
status.listing_status_id,
status.listing_status_desc
FROM listings AS l,
subdivisions AS sub,
bedrooms AS beds,
listing_status AS status
WHERE l.mls = '".$mls."'
AND l.subdivision_id = sub.id
AND l.beds_id = beds.beds_id
AND l.listing_status = status.listing_status_id
";
$result = mysql_query($query,$dbh);
return $result;
}
The only thing I can think of is that it isn't finding the $dbh variable. That's included in a different file. Do I need it?
Any help from the experts would be greatly appreciated! Thank you!