Page Arguments and Dynamic Pages 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' =&gt; 'City Listings',
        'page callback' =&gt; 'business_listings',
        'access arguments' =&gt; array('access content'),
        'page arguments' =&gt; array('states', 'city_names'),
    );

    return $items;
}


/*
** State Listings
*/

function listing_states($state){
    $state = array( 
        'alabama' =&gt; t('Alabama'),
        'alaska' =&gt; t('Alaska'),
        'arizona' =&gt; 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 .= '&lt;div class="city-wrapper"&gt;';
    foreach ($dbquery as $dbrow) {
        $cityname .='&lt;div class="cityname" style="float:left; width:200px;"&gt;';
        $cityname .= '&lt;a href="'.arg(2).'/'.strtolower(urlencode($dbrow-&gt;CityName)).'"&gt;'.$dbrow-&gt;CityName.'&lt;/a&gt;';
        $cityname .= '&lt;/div&gt;';
    }
    $cityname .= '&lt;/div&gt;';

    return array('states' =&gt; $states, 'city_names' =&gt; $cityname);
}
I believe you want to change your listings_menu()

function listings_menu() {
    $items = array();

    $items['site/listings/%'] = array(
        'title' =&gt; 'City Listings',
        'page callback' =&gt; 'business_listings',
        'access arguments' =&gt; array('access content'),
        'page arguments' =&gt; array(3),
    );

    return $items;
}


Then you need to change your listings to accept that argument

function business_listings($states){
  $states = listing_states($states);

  $dbquery = db_query("SELECT DISTINCT CityName FROM {zipcodes} WHERE StateName = '".ucfirst(arg(2))."' ORDER BY CityName ASC");

  $cityname = '';
  $cityname .= '&lt;div class="city-wrapper"&gt;';
  foreach ($dbquery as $dbrow) {
      $cityname .='&lt;div class="cityname" style="float:left; width:200px;"&gt;';
      $cityname .= '&lt;a href="'.arg(2).'/'.strtolower(urlencode($dbrow-&gt;CityName)).'"&gt;'.$dbrow-&gt;CityName.'&lt;/a&gt;';
      $cityname .= '&lt;/div&gt;';
  }
  $cityname .= '&lt;/div&gt;';

  return array('states' =&gt; $states, 'city_names' =&gt; $cityname);
}