Jump to content

Recommended Posts

[code]<?
      include("functions.php");
      
    query_states();
?>[/code]

How do I make it so when you click on the a link in the query_states function it will then look for cities in that state, with out having to make a new file to return the results. I dont know how to do it, but I assume it would be something like:
[code]<?
      include("functions.php");
      
    if ($states="null" than do query_states(); Which will show all the states to chose from.
                if ($states="" than do query_cities(); Which will now display the cities to the selected state.
                if ($cities="" than do query_businesses(); Which now will display the businesses to the selected city.
?>[/code]

Clearly I know that script will not work but what will make it work or should I go about it differently?

Link to comment
https://forums.phpfreaks.com/topic/11686-something-simple-i-am-sure/
Share on other sites

Ok this can be done simply.

add a link as page.php?state=<?=$state_id?> beside the state the user can choose (goes for city or whatever subsections you have)

then just add this:
[code]
if (isset ($_GET['state']) && mysql_num_rows (mysql_query ("SELECT `state_id` FROM `states` WHERE `state_id` = '".$_GET['state']."'")) != 0) // this check that $_GET['state'] exists in the db table of states
{
  $sql = "SELECT * FROM `cities` WHERE `state` = '".$_GET['state']."'"; // set the sql query to list the cities with the state tag equal to the state id which was inputted
}
[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.