View Full Version : New to PHP, Need help
ChrisC
02-28-2001, 09:38 AM
While waiting for my php/mysql books to arrive, I delved into the php/sql tutorial posted in the hosting matters mysql tutorial section. After completion, I am now ready to try my first php script to fulfill a requirement I have. What it entails is to connect to a mysql database of addresses, and using a form allow a user to enter in the address information i.e. 123 n. elm st. and based on that query pull and display information from one field only initially. My question is that I have not been able to find an example where the users address number will be used to query two tables 'lo_range' and 'hi_range'.
I hope this makes sense.
kevin
02-28-2001, 10:20 AM
It's very easy to include more than 1 table in your query.
"SELECT * FROM lo_range,hi_range"
If you've got a field in each table with the same name (for example 'address') that you want to query you would have to use:
$sql = SELECT lo_range.address,hi_range.address FROM lo_range,hi_range;
$res = mysql_query($sql) or die();
And then put those into variables:
while($myrow = mysql_fetch_array($res))
{
$lo_address = $myrow["lo_range.address"];
$hi_address = $myrow["hi_range.address"];
}
chrisc
02-28-2001, 11:57 AM
I apologize for the previous inaccuracies in my previous post. I want a form where users can enter in their address. The Form will have 7 input fields number,direction,name,type,post_dir,citycode,zipco de with all being optional except name and zipcode. direction, type, post_dir,and citycode being dropdown. This form will submit a query to a table called vrstrt with fields of citycode, direction, name, type, post_dir, lo_range, hi_range, odd_even, precinct, grp,zipcode, and business. The query will need to make sure that the number input field on the forms submit is equal to or greater than the lo_range and less than or equal to the hi_range for that record and will then result and print display on the page the data within the precinct field for that record. I do not expect or desire the code for this task. I am new to php and just want to know if there are any resources available to find the answer or method to my project. I just need to know where to start.
chrisc
02-28-2001, 03:13 PM
Marty,
Am I on the right track?
<?php
if ($submit) {
// process form
while (list($name, $value) = each($HTTP_POST_VARS)) {
echo "$name = $value<br>\n";
}
} else{
// Display Form
?>
<form method="post" action="<?php echo $PHP_SELF?>">
<input type="text" name="number" size="6"> Address Number<p>
<select name="direction" size="1" tabindex="1">
<option selected>Optional</option>
<option value="N">N</option>
<option value="S">S</option>
<option value="E">E</option>
<option value="W">W</option>
<option value="NE">NE</option>
<option value="SE">SE</option>
<option value="NW">NW</option>
<option value="SW">SW</option>
</select> Pre Direction<p>
<input type="text" name="name" size="25" tabindex="2"> Name<p>
<select name="type" size="1" tabindex="3">
<option selected>pick one</option>
<option value="AVE">AVE</option>
<option value="BLVD">BLVD</option>
<option value="CIR">CIR</option>
<option value="CT">CT</option>
<option value="DR">DR</option>
<option value="FWY">FWY</option>
<option value="HWY">HWY</option>
<option value="LOOP">LOOP</option>
<option value="LN">LN</option>
<option value="MNR">MNR</option>
<option value="MT">MT</option>
<option value="PKWY">PKWY</option>
<option value="PL">PL</option>
<option value="RD">RD</option>
<option value="ST">ST</option>
<option value="TRL">TRL</option>
<option value="TER">TER</option>
<option value="TRCE">TRCE</option>
<option value="WAY">WAY</option>
</select> Type<p>
<select name="post_dir" size="1" tabindex="1">
<option selected>Optional</option>
<option value="N">N</option>
<option value="S">S</option>
<option value="E">E</option>
<option value="W">W</option>
<option value="NE">NE</option>
<option value="SE">SE</option>
<option value="NW">NW</option>
<option value="SW">SW</option>
</select> Post Direction<p>
<input type="text" name="zipcode" size="5" tabindex="4"> Zip Code<br>
<input type="submit" name="submit" value="Find Precinct!!">
</form>
<?php
} // end if
?>
<?
$db= MYSQL_CONNECT(localhost, *****, ******);
mysql_select_db(chambless_cc,$db);
?>
<?
if ($submit) {
$sql = "SELECT * FROM vrstrt WHERE (hi_range => '$number' and lo_range =<
'$number')";
$result = mysql_query($sql);
while ($myrow = mysql_fetch_array($result)) {
printf ("Precinct: %s\n<br>", $myrow["precinct"]);}}
?>
</body>
chrisc
03-01-2001, 12:32 PM
Marty,
Thank you
I found an error in the $sql statement => and =< should be >= and <=. Yesterday I received my MYSQL book and was able to put it to use. Thanks Again....
chrisc
03-05-2001, 03:05 PM
$sql = "SELECT * FROM vrstrt WHERE name = '$address' AND(hi_range >= '$number' and lo_range <= '$number')AND zipcode = '$zip'";
$result = mysql_query($sql);
while ($myrow = mysql_fetch_array($result)) {
printf ("Precinct: %s\n <br>", $myrow ["precinct"]);}}
In addition to making sure that $number is within the range, I have an additional requirement is to determing if $number is odd or even.
Once that is known could I compare the result to a odd or even column that would then result $myrow
To discribe this requirement, I have some precincts that fall within the same number range, however, a odd or even street number determines if its in precinct a or b.
vBulletin® v3.6.8, Copyright ©2000-2009, Jelsoft Enterprises Ltd.