Jump to content

How do I do this?


robin339

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.