I have a problem that is probably simple to fix. I have a list of states on my site, and each one is a link. Istead of creating a separate folder for each state to store items in I want to use a script that I created that pulls all results by the clicked on state from a database. how do i do this basically each state is a link, and if a user clicks on massachusetts i want the action of clicking on that link to pull all data from the table related to massachusetts do i do this? and if so what is the fuction that i add to my <a href to make the link call a php page.
<?php if(isset($_GET['state']){ extract($_GET); $db_query = "SQL SCRIPT ETC"; // do what ever you want it to do here } ?> <a href="samepage.php?state=arizona">Arizona</a> you can even make it easier to list all the states if your not doing it already the sql syntax may be wrong, im so used to using firebird sql instead of mysql <?php $query = mysql_query("SELECT STATE FROM STATES ORDER BY STATE"); while($row = mysql_fetch_assoc($query)){ extract($row); echo '<a href="samepage.php?state='.$STATE.'">'.$STATE.'</a>'; } //or pull it from a array $state_array = array("ALL THE STATES"); foreach($state_array as $state){ echo '<a href="samepage.php?state='.$state.'">'.$state.'</a>'; } ?>
That syntax is correct, brendon28; good examples. URL: http://www.example.com/state.php?state=queensland if([B]$_GET['state'][/B]){ [B]$state[/B] = mysql_query("SELECT * FROM [B]states[/B] WHERE [B]name[/B]='".[B]$_GET['state'][/B]."'"); [B]$state[/B] = mysql_fetch_assoc([B]$state[/B]); echo [B]$state['name'][/B]; } Code (markup): Multiple variables can be parsed like: state.php?state=queensland&city=brisbane&country=australia for more complicated queries.