jakebur01 Posted March 26, 2007 Share Posted March 26, 2007 I am attempting to create this dealer locator. The database and tables are all setup ok. I need some help with my code. I was hoping to get a few suggestions. I know what I want it to do. I would just like to learn and get this baby going. Locator.php <HTML> <?php $db = mysql_connect("localhost", "myuser", "mypassword"); mysql_select_db("mydatabase" ,$db) or die('Error connecting to database'); //here I am getting the zip code the user typed in and selecting the longitude and latitude off of that same row $Getzip = mysql_query("SELECT smithslo, smithsla, smithszi FROM zdat1 WHERE ('$formzip' = smithszi)",$db) or die('Error, could not find Zip Code.'); [color=blue] //My problem is somewhere in this area //here i am trying to get the area of which i want to extract from my zip code table $Maxlon = (smithslo + ".6000"); $Minlon = (smithslo - ".6000"); $Maxlat = (smithsla + ".6000"); $Minlat = (smithsla - ".6000"); //here i am trying to select the rows that are in that range, also it is spitting the error back at me that is on the line below. $Getziprange = mysql_query("SELECT smithszi FROM '$Getzip' WHERE (smithslo BETWEEN '$Maxlon' AND '$Minlon') AND (smithsla BETWEEN '$Maxlat' AND '$Minlat')",$db) or die('Error, could not find Zip Codes within range.'); [/color] //here i am trying to select the rows that have the same zip codes as the ones i selected $Getdealer = mysql_query("SELECT Dealer, Address, City, State, Zip, Phone FROM learndb WHERE ('$Getziprange' = Zip)",$db) or die('Error retrieving dealers!'); if ($Shin) { mysql_query("SELECT Dealer, Address, City, State, Zip, Phone FROM '$Getdealer' WHERE (smiths_shin = 1)",$db) or die('Error retrieving Shindiawa dealers.'); echo "<TABLE BORDER=1>"; echo"<TR><TD><B>Dealer</B><TD><TD><TD><TD><TD><TD><B>Address</B><TD><TD><TD><TD><TD><TD><B>City</B><TD><TD><TD><TD><TD><TD><B>State</B><TD><TD><TD><TD><TD><TD><B>Zip Code</B><TD><TD><TD><TD><TD><TD><B>Phone Number</B></TR>"; while ($Getshin = mysql_fetch_array($Getdealer)) { echo "<TR><TD>"; echo $Getshin["Dealer"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getshin["Address"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getshin["City"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getshin["State"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getshin["Zip"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getshin["Phone"]; } echo "</TABLE>"; } if ($Little) { mysql_query("SELECT Dealer, Address, City, State, Zip, Phone FROM '$Getdealer' WHERE (smiths_lw = 1)",$db) or die('Error retrieving Little Wonder dealers.'); echo "<TABLE BORDER=1>"; echo"<TR><TD><B>Dealer</B><TD><TD><TD><TD><TD><TD><B>Address</B><TD><TD><TD><TD><TD><TD><B>City</B><TD><TD><TD><TD><TD><TD><B>State</B><TD><TD><TD><TD><TD><TD><B>Zip Code</B><TD><TD><TD><TD><TD><TD><B>Phone Number</B></TR>"; while ($Getlittle = mysql_fetch_array($Getdealer)) { echo "<TR><TD>"; echo $Getlittle["Dealer"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getlittle["Address"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getlittle["City"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getlittle["State"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getlittle["Zip"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getlittle["Phone"]; } echo "</TABLE>"; } if ($Man) { mysql_query("SELECT Dealer, Address, City, State, Zip, Phone FROM '$Getdealer' WHERE (smiths_m = 1)",$db) or die('Error retrieving Mantis dealers.'); echo "<TABLE BORDER=1>"; echo"<TR><TD><B>Dealer</B><TD><TD><TD><TD><TD><TD><B>Address</B><TD><TD><TD><TD><TD><TD><B>City</B><TD><TD><TD><TD><TD><TD><B>State</B><TD><TD><TD><TD><TD><TD><B>Zip Code</B><TD><TD><TD><TD><TD><TD><B>Phone Number</B></TR>"; while ($Getman = mysql_fetch_array($Getdealer)) { echo "<TR><TD>"; echo $Getman["Dealer"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getman["Address"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getman["City"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getman["State"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getman["Zip"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getman["Phone"]; } echo "</TABLE>"; } if ($Class) { mysql_query("SELECT Dealer, Address, City, State, Zip, Phone FROM '$Getdealer' WHERE (smiths_cl = 1)",$db) or die('Error retrieving Classin dealers.'); echo "<TABLE BORDER=1>"; echo"<TR><TD><B>Dealer</B><TD><TD><TD><TD><TD><TD><B>Address</B><TD><TD><TD><TD><TD><TD><B>City</B><TD><TD><TD><TD><TD><TD><B>State</B><TD><TD><TD><TD><TD><TD><B>Zip Code</B><TD><TD><TD><TD><TD><TD><B>Phone Number</B></TR>"; while ($Getclass = mysql_fetch_array($Getdealer)) { echo "<TR><TD>"; echo $Getclass["Dealer"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getclass["Address"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getclass["City"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getclass["State"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getclass["Zip"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getclass["Phone"]; } echo "</TABLE>"; } if ($Smiths) { mysql_query("SELECT Dealer, Address, City, State, Zip, Phone FROM '$Getdealer' WHERE (smiths_smith = 1)",$db) or die('Error retrieving Smiths dealers.'); echo "<TABLE BORDER=1>"; echo"<TR><TD><B>Dealer</B><TD><TD><TD><TD><TD><TD><B>Address</B><TD><TD><TD><TD><TD><TD><B>City</B><TD><TD><TD><TD><TD><TD><B>State</B><TD><TD><TD><TD><TD><TD><B>Zip Code</B><TD><TD><TD><TD><TD><TD><B>Phone Number</B></TR>"; while ($Getsmith = mysql_fetch_array($Getdealer)) { echo "<TR><TD>"; echo $Getsmith["Dealer"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getsmith["Address"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getsmith["City"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getsmith["State"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getsmimth["Zip"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getsmith["Phone"]; } echo "</TABLE>"; } if ($Troy) { mysql_query("SELECT Dealer, Address, City, State, Zip, Phone FROM '$Getdealer' WHERE (smiths_troy = 1)",$db) or die('Error retrieving Troy Bilt dealers.'); echo "<TABLE BORDER=1>"; echo"<TR><TD><B>Dealer</B><TD><TD><TD><TD><TD><TD><B>Address</B><TD><TD><TD><TD><TD><TD><B>City</B><TD><TD><TD><TD><TD><TD><B>State</B><TD><TD><TD><TD><TD><TD><B>Zip Code</B><TD><TD><TD><TD><TD><TD><B>Phone Number</B></TR>"; while ($Gettroy = mysql_fetch_array($Getdealer)) { echo "<TR><TD>"; echo $Gettroy["Dealer"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Gettroy["Address"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Gettroy["City"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Gettroy["State"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Gettroy["Zip"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Gettroy["Phone"]; } echo "</TABLE>"; } if ($White) { mysql_query("SELECT Dealer, Address, City, State, Zip, Phone FROM '$Getdealer' WHERE (smiths_white = 1)",$db) or die('Error retrieving White Outdoor dealers.'); echo "<TABLE BORDER=1>"; echo"<TR><TD><B>Dealer</B><TD><TD><TD><TD><TD><TD><B>Address</B><TD><TD><TD><TD><TD><TD><B>City</B><TD><TD><TD><TD><TD><TD><B>State</B><TD><TD><TD><TD><TD><TD><B>Zip Code</B><TD><TD><TD><TD><TD><TD><B>Phone Number</B></TR>"; while ($Getwhite = mysql_fetch_array($Getdealer)) { echo "<TR><TD>"; echo $Getwhite["Dealer"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getwhite["Address"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getwhite["City"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getwhite["State"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getwhite["Zip"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getwhite["Phone"]; } echo "</TABLE>"; } if ($Oregon) { mysql_query("SELECT Dealer, Address, City, State, Zip, Phone FROM '$Getdealer' WHERE (smiths_oregon = 1)",$db) or die('Error retrieving Oregon dealers.'); echo "<TABLE BORDER=1>"; echo"<TR><TD><B>Dealer</B><TD><TD><TD><TD><TD><TD><B>Address</B><TD><TD><TD><TD><TD><TD><B>City</B><TD><TD><TD><TD><TD><TD><B>State</B><TD><TD><TD><TD><TD><TD><B>Zip Code</B><TD><TD><TD><TD><TD><TD><B>Phone Number</B></TR>"; while ($Getoregon = mysql_fetch_array($Getdealer)) { echo "<TR><TD>"; echo $Getoregon["Dealer"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getoregon["Address"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getoregon["City"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getoregon["State"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getoregon["Zip"]; echo "<TD><TD><TD><TD><TD><TD>"; echo $Getoregon["Phone"]; } echo "</TABLE>"; } ?> </HTML> and here is the form <form id="form2" name="form2" method="post" action="dealerlocator/locator.php"> <table width="579"> <!--DWLayoutTable--> <tr> <td width="569"><label> </label> <div align="center"> <input type="radio" name="Select Product" value="Shin" /> <img src="Images/shin.gif" alt="Shindiawa" width="95" height="33" /><span class="style1">---- <input type="radio" name="Select Product" value="Little" /> <img src="Images/little.gif" alt="Little Wonder" width="95" height="33" />---- <input type="radio" name="Select Product" value="Man" /> <img src="Images/mantis.gif" alt="Mantis" width="95" height="33" />---- <input type="radio" name="Select Product" value="Class" /> <img src="Images/classin.gif" alt="Classin" width="95" height="33" /></span></div> <p><span class="style1">kjh lkjhlkjh kjh k </span></p></td> </tr> <tr> <td><label> </label> <div align="center"> <input type="radio" name="Select Product" value="Smiths" /> <img src="Images/smith-logo.gif" alt="Smiths" width="73" height="48" /><span class="style1">------ <input type="radio" name="Select Product" value="Troy" /> <img src="Images/troy.gif" alt="Troy Bilt" width="95" height="33" />---- <input type="radio" name="Select Product" value="White" /> <img src="Images/white.gif" alt="white Outdoor" width="95" height="33" />---- <input type="radio" name="Select Product" value="Oregon" /> <img src="Images/oregon copy.gif" alt="Oregon" width="95" height="33" /></span></div></td> </tr> </table> <div class="style1">Content for New Div Tag Goes Here <div>Content for New Div Tag Goes Here <div class="style26"><strong>Enter Your Zip Code Here: <label for="textfield"></label> </strong> <input type="text" name="formzip" id="textfield" /> <span class="style1">----- <input type="submit" name="Submit" value="Get Dealers!" id="Submit" /> </span></div> </div> </div> <p class="style1"> </p> </form> thank you, Jake Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/ Share on other sites More sharing options...
per1os Posted March 26, 2007 Share Posted March 26, 2007 Do you know how to do html, Why soo many <td> without a </td>.... and why soo many <td>'s ??? Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215309 Share on other sites More sharing options...
jakebur01 Posted March 26, 2007 Author Share Posted March 26, 2007 I am just learning. I am gettin back my error in the section below. $Maxlon = (smithslo + .6000); $Minlon = (smithslo - .6000); $Maxlat = (smithsla + .6000); $Minlat = (smithsla - .6000); $Getziprange = mysql_query("SELECT smithszi FROM '$Getzip' WHERE (smithslo BETWEEN '$Maxlon' AND '$Minlon') AND (smithsla BETWEEN '$Maxlat' AND '$Minlat')",$db) or die('Error, could not find Zip Codes within range.'); smithslo and smithsla are the longitude and latitudes I selected from my zip code table. Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215312 Share on other sites More sharing options...
trq Posted March 26, 2007 Share Posted March 26, 2007 What is the error? Have you defined smithslo as a constant? otherwise, if its meant to be a variable your missing the $ Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215314 Share on other sites More sharing options...
trq Posted March 26, 2007 Share Posted March 26, 2007 Actually, this code is all over the place. mysql_query returns a result resource, to start with, Id'e suggest you at least look at the man to see if you can figure out how it works. Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215315 Share on other sites More sharing options...
jakebur01 Posted March 26, 2007 Author Share Posted March 26, 2007 I'm sorry for my ignorance. I thought I might could make this work. Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215320 Share on other sites More sharing options...
trq Posted March 26, 2007 Share Posted March 26, 2007 You could, but you at least need a basic understanding of what is going on. Im not palming your problem off, merely suggesting you read some tutorials or at minimum, the manual for mysql_query. Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215322 Share on other sites More sharing options...
jakebur01 Posted March 26, 2007 Author Share Posted March 26, 2007 I appreciate you helping me. Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215323 Share on other sites More sharing options...
Leeder Posted March 26, 2007 Share Posted March 26, 2007 Also, no html tags in caps <HTML> = not good. <html> = beautiful Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215337 Share on other sites More sharing options...
DeathStar Posted March 26, 2007 Share Posted March 26, 2007 Leeder that does not mater so much! the mistake commonly made with <html> is: <html and /html> Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215355 Share on other sites More sharing options...
jakebur01 Posted March 26, 2007 Author Share Posted March 26, 2007 Am I trying to go through to many resources? or Do I have too many mysql_query's goin on? Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215395 Share on other sites More sharing options...
tarun Posted March 26, 2007 Share Posted March 26, 2007 Also, no html tags in caps <HTML> = not good. <html> = beautiful Why....? I Always Write HTML In Caps I Just Looks Nicer, Neater And Is Easier To Read (In My Opinion) Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215401 Share on other sites More sharing options...
trq Posted March 26, 2007 Share Posted March 26, 2007 Am I trying to go through to many resources? or Do I have too many mysql_query's goin on? As I said, mysql_query() returns a result resource, not what you think. You need to use it in combination with mysql_fetch_assoc() to actually get a result. A simple example. <?php // connect to db. $sql = "SELECT foo,bar FROM tbl"; // store your result resource in $result. if ($result = mysql_query($sql)) { // check $result holds records if (mysql_num_rows($result)) { // fetch the first row. $row = mysql_fetch_assoc($result); // display record. echo $row['foo']; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215402 Share on other sites More sharing options...
jakebur01 Posted March 26, 2007 Author Share Posted March 26, 2007 I see what your saying. I have want I want selected, but I need to actually retrieve it as well. thank you, I will play with this Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215407 Share on other sites More sharing options...
trq Posted March 26, 2007 Share Posted March 26, 2007 I see what your saying. Well then, take these two lines for instance. $Getziprange = mysql_query("SELECT smithszi FROM '$Getzip' WHERE (smithslo BETWEEN '$Maxlon' AND '$Minlon') AND (smithsla BETWEEN '$Maxlat' AND '$Minlat')",$db) or die('Error, could not find Zip Codes within range.'); $Getdealer = mysql_query("SELECT Dealer, Address, City, State, Zip, Phone FROM learndb WHERE ('$Getziprange' = Zip)",$db) or die('Error retrieving dealers!'); In your second query you have the variable $Getziprange, what do you expect this to be? It is a result resource. Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215416 Share on other sites More sharing options...
jakebur01 Posted March 26, 2007 Author Share Posted March 26, 2007 Like this? $zip = mysql_query("SELECT smithslo, smithsla, smithszi FROM zdat1 WHERE ('$formzip' = smithszi)",$db) or die('Error, could not find Zip Code.'); $Getzip = mysql_fetch_assoc($zip)or die('Error, could not fetch $Getzip.'); $Maxlon = (smithslo + .6000); $Minlon = (smithslo - .6000); $Maxlat = (smithsla + .6000); $Minlat = (smithsla - .6000); $ziprange = mysql_query("SELECT smithszi FROM '$Getzip' WHERE (smithslo BETWEEN '$Maxlon' AND '$Minlon') AND (smithsla BETWEEN '$Maxlat' AND '$Minlat')",$db) or die('Error, could not find Zip Codes within range.'); $Getziprange = mysql_fetch_assoc($ziprange); $Getdealer = mysql_query("SELECT Dealer, Address, City, State, Zip, Phone FROM learndb WHERE ('$Getziprange' = Zip)",$db) or die('Error retrieving dealers!'); After these last changes I am still getting the error: 'Error, could not find Zip Codes within range. Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215424 Share on other sites More sharing options...
per1os Posted March 26, 2007 Share Posted March 26, 2007 Also, no html tags in caps <HTML> = not good. <html> = beautiful Why....? I Always Write HTML In Caps I Just Looks Nicer, Neater And Is Easier To Read (In My Opinion) Caps are not xhtml compliant. That is why he stated to do them in lowercase. HTML is not picky about case, just making it standard is the picky portion. Heck you could do the tags like <HtMl> </HTml> and it would work just fine. But to be compliant with W3C standards, lowercase is the way to go. Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215426 Share on other sites More sharing options...
jakebur01 Posted March 26, 2007 Author Share Posted March 26, 2007 Ha, it's a good thing for me to keep in mind for future purposes. Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215430 Share on other sites More sharing options...
trq Posted March 26, 2007 Share Posted March 26, 2007 Like this? Thats more like it, but your code still has plenty of issues. For starters, always wrap your queries within tests, lines like.... $Getziprange = mysql_fetch_assoc($ziprange); Assume your query succeeded which is very error prone and a bad habit to get into. Also, this bit... $Maxlon = (smithslo + .6000); $Minlon = (smithslo - .6000); $Maxlat = (smithsla + .6000); $Minlat = (smithsla - .6000); What is smithsla ? Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215433 Share on other sites More sharing options...
jakebur01 Posted March 26, 2007 Author Share Posted March 26, 2007 smithsla is a column in my zip code table that stands for latitude... and smithslo is the longitude column.................. I got in a habit of naming the columns thing that I can rememeber... I was having trouble getting my data to go in to the table in the beginning. I first had my longitude column named Long, I found the word "Long" on the list of words not to use. Since then I have been naming my stuff odd abbeviations and names. The zip code table which I have labeled "zdat1" holds 40,000 zip codes. Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215439 Share on other sites More sharing options...
jakebur01 Posted March 26, 2007 Author Share Posted March 26, 2007 You can see the page that I am trying to get going here: http://www.smithssc.com/dealerlocator.php Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215445 Share on other sites More sharing options...
trq Posted March 26, 2007 Share Posted March 26, 2007 If that is the case then you would need something like.... <?php $sql = "SELECT smithslo, smithsla, smithszi FROM zdat1 WHERE ('$formzip' = smithszi)" if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($zip); $Maxlon = $row['smithslo'] + 6000; $Minlon = $row['smithslo'] - 6000; $Maxlat = $row['smithsla'] + 6000; $Minlat = $row['smithsla'] - 6000; } } ?> Honestly, as I said. This code is not ready to be stepped through with someone pointing out all the issues. I suggest you read up on how all these functions work and apply them to your code. Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215451 Share on other sites More sharing options...
jakebur01 Posted March 26, 2007 Author Share Posted March 26, 2007 ok Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215454 Share on other sites More sharing options...
Leeder Posted March 26, 2007 Share Posted March 26, 2007 Who is Smith? Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215502 Share on other sites More sharing options...
jakebur01 Posted March 27, 2007 Author Share Posted March 27, 2007 You could, but you at least need a basic understanding of what is going on. Im not palming your problem off, merely suggesting you read some tutorials or at minimum, the manual for mysql_query. Where would be a good place to find tutorials related to this? I want to learn!! Point me in the right direction. Quote Link to comment https://forums.phpfreaks.com/topic/44334-i-need-suggestions/#findComment-215854 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.