<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[PHP Forums - PHP script to select state]]></title>
	<link rel="self" href="http://www.phpforums.org/feed-atom-topic29.xml"/>
	<updated>2010-08-06T07:29:32Z</updated>
	<generator>PunBB</generator>
	<id>http://phpforums.org/topic29-php-script-to-select-state.html</id>
		<entry>
			<title type="html"><![CDATA[Re: PHP script to select state]]></title>
			<link rel="alternate" href="http://phpforums.org/post72.html#p72"/>
			<content type="html"><![CDATA[<p>You can place a select box with all the available states in contacts and populate it in a select box.&nbsp; Then after that based on the selected values pass query to the database</p><div class="codebox"><pre><code>&lt;select name=&quot;state&quot;&gt;
&lt;?php
$sql   =  &quot;SELECT DISTINCT ( state ) FROM contacts ORDER BY state&quot;;
$res = mysql_query( $sql ) or die( mysql_error());
while( $row = mysql_fetch_object( $res ) ){
           echo &#039;&lt;option = &#039;&quot;. $row-&gt;state .&quot;&#039;&gt;&#039;. $row-&gt;state .&#039;&lt;/option&gt;&#039;;
}
?&gt;
&lt;/select&gt;
&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;search&quot;&gt;</code></pre></div><p>Then in the landing page do the following code<br /></p><div class="codebox"><pre><code>&lt;?php 
if( isset( $_POST[&#039;state&#039;] ) ){
       $sql = &quot;SELECT * FROM contacts WHERE state = &quot;&quot;.  $_POST[&#039;state&#039;] .&quot;&#039;&quot;;
       //Remaining Operations
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[aneeshrp]]></name>
				<uri>http://phpforums.org/user46.html</uri>
			</author>
			<updated>2010-08-06T07:29:32Z</updated>
			<id>http://phpforums.org/post72.html#p72</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[PHP script to select state]]></title>
			<link rel="alternate" href="http://phpforums.org/post58.html#p58"/>
			<content type="html"><![CDATA[<p>I have a database table called contacts with a table in it called addresses. The fields in the addresses table are firstname, lastname, address, city, state, zip, areacode and phonenumber. (The state field is a 2 character text field.) I want to ask the user for a state and then I want to display all the records for that state only. Can anyone help me? </p><p>Thanks, </p><p>Andrew</p>]]></content>
			<author>
				<name><![CDATA[andrewgrz]]></name>
				<uri>http://phpforums.org/user36.html</uri>
			</author>
			<updated>2010-06-12T03:26:22Z</updated>
			<id>http://phpforums.org/post58.html#p58</id>
		</entry>
</feed>

