thunderdogg Posted March 30, 2007 Share Posted March 30, 2007 I have a SQL database which contains a PrimaryID, address, zipcode, and some data. THis info is put into the database by users thru HTML forms. I'd like to be able to set up an IF statment which will plot only all the locations of the database where the users's zipcode entry matches the zipcode of data already in the database. (ie the user says his ZIPCODE is 90210, the code will go thru the database and only take the info from other 90210 entries and put all of them on the map for my user to see). THe code i've currently got will show ALL of the points. Does anybody have a suggestion for how to do this? I've been having trouble writing an IF statement to pull this off. I'm fairly new to PHP / SQL. Like i said before my SQL table has a primaryID (id) and the address info (address) and zipcode (zipcode) etc... I think those are really the only variables that would need to be called. THe code is below: ------------------------------------------------------ <?php $link = mysql_connect("www.freesql.org:3306", "login", "password") or die("Could not connect: " . mysql_error()); mysql_selectdb("jdata",$link) or die ("Can\'t use dbmapserver : " . mysql_error()); $result = mysql_query("SELECT * FROM usefuldata ",$link); if (!$result) { echo "no results "; } while($row = mysql_fetch_array($result)) { echo "var point = new GLatLng" . $row['latlon'] . ";\n"; echo "var marker = createMarker(point, '" . addslashes($row['Name']) . "','" . addslashes($row['Address']) . "');\n"; echo "map.addOverlay(marker);\n"; echo "\n"; } echo "map.setCenter(point);\n"; mysql_close($link); ?> Link to comment https://forums.phpfreaks.com/topic/44992-solved-help-making-an-if-statement-using-the-sql-primaryid-value/ Share on other sites More sharing options...
AndyB Posted March 30, 2007 Share Posted March 30, 2007 SELECT * from tablename WHERE zipcodefield = '$user_entered_value' Link to comment https://forums.phpfreaks.com/topic/44992-solved-help-making-an-if-statement-using-the-sql-primaryid-value/#findComment-218413 Share on other sites More sharing options...
thunderdogg Posted March 31, 2007 Author Share Posted March 31, 2007 hmm i dont think it's that easy. Every line in the database is gonna have a '$user_entered_value' for the zipcode. THe problem is that I need to somehow ensure that i get the actual user entered one. Once they use a HTML form to pass it to the database, i'm not passing the user variable any further. So i'd have to get it back from the database. TO do that is there a means of forcing the SQL database to pull the last line input? Or would it be easier to just keep posting the userinput data all the way from start to finish instead of sending it to the database and then trying to get it back out? Link to comment https://forums.phpfreaks.com/topic/44992-solved-help-making-an-if-statement-using-the-sql-primaryid-value/#findComment-218487 Share on other sites More sharing options...
AndyB Posted March 31, 2007 Share Posted March 31, 2007 Oh it is that easy. I realise that every row has some value. but the rows you want to select are those where some browsing user has entered some specific zip code in a form that you're using to let them display what's in the same zip code as they entered Link to comment https://forums.phpfreaks.com/topic/44992-solved-help-making-an-if-statement-using-the-sql-primaryid-value/#findComment-218490 Share on other sites More sharing options...
thunderdogg Posted March 31, 2007 Author Share Posted March 31, 2007 After thinking about it i just did what i mentioned, which was to reset the userinput value to a variable on each page so it constantly came through. this was just as easy (if not easier) than repulling it back up from the SQL. I dont know that i phrased the question right, since i dont think it was ever clear what the problem was. I use the WHERE command to pull the right data from my table but the problem was GETTING the control varialbe to pull from. anyways, i did appreciate your quick responses. Link to comment https://forums.phpfreaks.com/topic/44992-solved-help-making-an-if-statement-using-the-sql-primaryid-value/#findComment-218502 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.