i have just being trying to create a function to show the latest 30 listings from a selected area only , ie Arizona


i have just used the code from the addon featured by class and just changed a few sql quieries to try to grab just the latest 30 listings from that area

can anyone who nos anything about the correct sql to be used, please help in the best way to do this

heres my code for the function, not tested yet, but i hope it will work
i plan to use it on different places on my site calling it by

latest_listings($region)


Code:
function latest_listings($region) {
	global $config, $conn, $db_type;
	require_once($config['basepath'] . '/include/misc.inc.php');
	$misc = new misc();
	$check_limit = "0";
	$display = '';
// *****************************************************************************
	// REGION TO GRAB LISTINGS FROM
	//$listingregion = $region;
	$listingregion = "Arizona";
// *****************************************************************************
	// QUANTITY OF LISTINGS
	$quantity = 30;
// *****************************************************************************
	// GRAB LISTING ID FOR THIS REGION

	$sql = "SELECT listingsdb_id FROM " . $config['table_prefix_no_lang'] . "listingsdbelements WHERE listingsdbelements_field_value = $listingregion ORDER BY listingsdb_id DESC";
	$recordSet = $conn->Execute($sql);
	while (!$recordSet->EOF) {
		if($quantity > $check_limit) {
			$listingID = $recordSet->fields['listingsdb_id'];
			// CHECK IF THIS LISTING ID IS ACTIVE AND NOT EXPIRED - ALSO GRAB LISTING TITLE
			if ($config['use_expiration'] === "1") {
				$sql2 = "SELECT listingsdb_title FROM " . $config['table_prefix'] . "listingsdb WHERE (listingsdb_id = $listingID AND listingsdb_active = 'yes' AND listingsdb_expiration > " . $conn->DBDate(time()) . ")";
				} else {
				$sql2 = "SELECT listingsdb_title FROM " . $config['table_prefix'] . "listingsdb WHERE (listingsdb_id = $listingID AND listingsdb_active = 'yes')";
				}
			$recordSet2 = $conn->Execute($sql2);
				$listingTITLE = $recordSet2->fields['listingsdb_title'];
				$featuredYES = $recordSet2->fields['listingsdb_featured'];
			if($listingTITLE == $listingTITLE) {
				// IT IS SET AS FEATURED - CONTINUE
				$check_limit++;

				// GRAB THE THUMB ORDERED BY RANK
				$sql2 = "SELECT listingsimages_thumb_file_name FROM " . $config['table_prefix'] . "listingsimages WHERE listingsdb_id = $listingID ORDER BY listingsimages_rank";
				$recordSet2 = $conn->Execute($sql2);
				if ($recordSet2->RecordCount() > 0) {
					$listingTHUMB = $misc->make_db_unsafe ($recordSet2->fields['listingsimages_thumb_file_name']);
					$imagedata = GetImageSize("$config[listings_upload_path]/$listingTHUMB");
					$imagewidth = $imagedata[0];
					$imageheight = $imagedata[1];
					$shrinkage = $config['thumbnail_width'] / $imagewidth;
					$featured_thumb_width = $imagewidth * $shrinkage;
					$featured_thumb_height = $imageheight * $shrinkage;
					$listingTHUMBIMAGE = '<img src="' . $config['baseurl']. '/images/listing_photos/' . $listingTHUMB . '" width="' . $featured_thumb_width . '" height="' . $featured_thumb_height . '" alt="' . $listingTITLE . '" />';
					}
				// IF NO IMAGE DISPLAY NOPHOTO.GIF
				if ($recordSet2->RecordCount() == 0) {
					if ($config['show_no_photo'] == 1) {
						$listingTHUMB = $config['baseurl'] . '/images/nophoto.gif';
						$imagedata = GetImageSize("images/nophoto.gif");
						$imagewidth = $imagedata[0];
						$imageheight = $imagedata[1];
						$shrinkage = $config['thumbnail_width'] / $imagewidth;
						$featured_thumb_width = $imagewidth * $shrinkage;
						$featured_thumb_height = $imageheight * $shrinkage;
						$listingTHUMBIMAGE = '<img src="' . $listingTHUMB . '" width="' . $featured_thumb_width . '" height="' . $featured_thumb_height . '" alt="No Photo" />';
						} else {
						// display nothing
						$listingTHUMBIMAGE = '';
						}
					}
// *****************************************************************************
// DISPLAY TO THE PAGE
			$display .= '
<div style="clear:both;">&nbsp;</div>
<div style="float:left; text-align:center;">
<a href="index.php?action=listingview&amp;listingID=' . $listingID . '" title="' . $listingTITLE . '">
' . $classNAME . '<br />  ' . $listingTHUMBIMAGE . '<br /> ' . $listingTITLE . '
</a> </div> ';
			$display .= '<div style="clear:both;">&nbsp;</div>';
// *****************************************************************************
				}
			}
		$recordSet->MoveNext();
		}
	return $display;
	}
anyone who could point me in the right direction in the correct sql quires for this