robin339 Posted March 9, 2007 Share Posted March 9, 2007 Hello guys, How do i do this? Lets say I have 3 fields. Name, Phone and zipcode. I insert all 3 values in mysql. Someone on my site has the name and/or the phone and needs to find out that person's zip code. How can the page pull up the complete info using the partial info provided? Thanks Link to comment https://forums.phpfreaks.com/topic/41923-how-do-i-do-this/ Share on other sites More sharing options...
benjaminbeazy Posted March 9, 2007 Share Posted March 9, 2007 $sql = "SELECT * from `persons` WHERE `name`='$name' OR `phone`='$phone'"; $result = mysql_query($sql); while($row = mysql_fetch_object($result)){ echo "Name = $row->name, Phone = $row->phone, Zip = $row->zip<br>"; } Link to comment https://forums.phpfreaks.com/topic/41923-how-do-i-do-this/#findComment-203274 Share on other sites More sharing options...
rameshfaj Posted March 9, 2007 Share Posted March 9, 2007 What u need is to have a unique key for the entry.Just like the citizenship number is a unique key in a country. Lets suppose, the user enters the field1,field2,field3.If the user only enters one of them and the one is not unique then the entries with similar entries will be selected.If the word is unique,then only the particular one is selected. Query: $field1=$_POST["field1"]; $query="select *from mytable where myfield='".$field1."'";//u can also have like instead of= sign in the query. $result=mysql_query($query); echo"$result"; Link to comment https://forums.phpfreaks.com/topic/41923-how-do-i-do-this/#findComment-203293 Share on other sites More sharing options...
robin339 Posted March 10, 2007 Author Share Posted March 10, 2007 Awesome !! Thanks both of you guys !! One more question, how do i "echo" Name not found? Thanks again Link to comment https://forums.phpfreaks.com/topic/41923-how-do-i-do-this/#findComment-204150 Share on other sites More sharing options...
robin339 Posted March 10, 2007 Author Share Posted March 10, 2007 Also, if the same person has more than 1 info in the mysql, how do you show the next set of data in the next row. Instead of Name = billy , phone= 111-111-1111, zip= 20011 , Name = billy , phone = 222-222-2222, zip = 55000 I wanna show like this : Name = billy , phone= 111-111-1111, zip= 20011 Name = billy , phone = 222-222-2222, zip = 55000 Thanks again Link to comment https://forums.phpfreaks.com/topic/41923-how-do-i-do-this/#findComment-204152 Share on other sites More sharing options...
JasonLewis Posted March 10, 2007 Share Posted March 10, 2007 like this? $sql = "SELECT * from `persons` WHERE `name`='$name' OR `phone`='$phone'"; $result = mysql_query($sql) or die("Error: ".mysql_error()); if(mysql_num_rows($result) == 0){ echo "No matches"; }else{ while($row = mysql_fetch_array($result)){ echo "Name: {$row['name']}, Phone: {$row['phone']}, Zip: {$row['zip']}<br>"; } } Link to comment https://forums.phpfreaks.com/topic/41923-how-do-i-do-this/#findComment-204156 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.