I am trying to make dynamic pages using hook menu which is going fine but the problem is I want to add page arguments for the states. For example if someone goes to the url and there isnt a state in the url like california for example(site/listings/california) it would show a page not found error, and if found it would list the listings I have looped out in my function.
Any Suggestions?
/*
** Hook Menu
*/
function listings_menu() {
$items = array();
$items['site/listings/%'] = array(
'title' => 'City Listings',
'page callback' => 'business_listings',
'access arguments' => array('access content'),
'page arguments' => array('states', 'city_names'),
);
return $items;
}
/*
** State Listings
*/
function listing_states($state){
$state = array(
'alabama' => t('Alabama'),
'alaska' => t('Alaska'),
'arizona' => t('Arizona'),
//ect.....
);
return $state;
}
/*
** Company Listings
*/
function business_listings(){
$states = listing_states(arg(2));
$dbquery = db_query("SELECT DISTINCT CityName FROM {zipcodes} WHERE StateName = '".ucfirst(arg(2))."' ORDER BY CityName ASC");
$cityname = '';
$cityname .= '<div class="city-wrapper">';
foreach ($dbquery as $dbrow) {
$cityname .='<div class="cityname" style="float:left; width:200px;">';
$cityname .= '<a href="'.arg(2).'/'.strtolower(urlencode($dbrow->CityName)).'">'.$dbrow->CityName.'</a>';
$cityname .= '</div>';
}
$cityname .= '</div>';
return array('states' => $states, 'city_names' => $cityname);
}