473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

i have a problem with my search page

123 100+
i have two simon in a field in my database called Fname and simon
in a field called Lname when i search for simon it will only display
one of the simon

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.     $link = mysql_connect( "localhost", "user2", "point" );
  4.     if ( ! $link )
  5.     die( "Couldn't connect to MySQL" );
  6.     mysql_select_db( "files", $link )
  7.     or die ( "Couldn't open $database: ".mysql_error() );
  8.  
  9.     if (isset($_POST["term"])){
  10.     $term = $_POST["term"];
  11.     //echo "$term";
  12.  
  13.     $result = mysql_query("SELECT * FROM user WHERE Fname like '%$term%' OR Lname like '%$term%'",$link);
  14.     $myrow = mysql_fetch_array($result);
  15.  
  16.     $Fname = $myrow["Fname"];
  17.     $Lname = $myrow["Lname"];
  18.     $Address = $myrow["Address"];
  19.     $Phone = $myrow["Phone no"];
  20.     $Email = $myrow["Email"];
  21.  
  22.  
  23.     echo "$Fname<br>";
  24.     echo "$Lname<br>";
  25.     echo "$Address<br>";
  26.     echo "$Phone<br>";
  27.     echo "$Email<br>";
  28.     }else {
  29.  
  30.     echo "search not found";
  31.     }
  32. ?>
  33.  
Dec 21 '08 #1
2 1073
dumm
10
Should be:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.     $link = mysql_connect( "localhost", "user2", "point" );
  4.     if ( ! $link )
  5.     die( "Couldn't connect to MySQL" );
  6.     mysql_select_db( "files", $link )
  7.     or die ( "Couldn't open $database: ".mysql_error() );
  8.  
  9.     if (isset($_POST["term"])){
  10.     $term = $_POST["term"];
  11.     //echo "$term";
  12.  
  13.     $result = mysql_query("SELECT * FROM user WHERE Fname like '%$term%' OR Lname like '%$term%'",$link);
  14.  
  15.     if(mysql_num_rows($result) > 0){
  16.  
  17.     while($myrow = mysql_fetch_assoc($result))
  18.     {
  19.  
  20.     $Fname = $myrow["Fname"];
  21.     $Lname = $myrow["Lname"];
  22.     $Address = $myrow["Address"];
  23.     $Phone = $myrow["Phone no"];
  24.     $Email = $myrow["Email"];
  25.  
  26.  
  27.     echo "$Fname<br>";
  28.     echo "$Lname<br>";
  29.     echo "$Address<br>";
  30.     echo "$Phone<br>";
  31.     echo "$Email<br>";
  32.  
  33.     } // end while    
  34.  
  35.     }else { // if no results found
  36.  
  37.     echo "search not found";
  38.     }
  39. ?>
  40.  
Right now you only fetch the first entry found.
Dec 21 '08 #2
Markus
6,050 Expert 4TB
You need to use mysql_fetch_array() to return an array of the results obtained from the database. You can then loop over this array to get all results.
Dec 21 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: CharitiesOnline | last post by:
Hello, I have set this script up to add paging to a search results page. Which on the first page works fine. I calculates how many pages there should be depending on the number of results returned...
8
by: Someone | last post by:
Hi, I wish to use a dictionary.com search box and want the results of a search to open in a new window. Is there a way to do this using their code? The copy and paste code is provided below. ...
2
by: David | last post by:
Sent this to alt.php a couple of days back, but doesn't look like I'll get an answer, so trying here. I'm trying to convert a script to use friendly URLs, I've done this before, but my PHP...
3
by: Aaron | last post by:
I'm trying to parse a table on a webpage to pull down some data I need. The page is based off of information entered into a form. when you submit the data from the form it displays a...
1
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and...
0
by: passion | last post by:
"Specialized Search Engines" along with Google Search Capability (2 in 1): http://specialized-search-engines.blogspot.com/ Billions of websites are available on the web and plenty of extremely...
13
by: jfarthing | last post by:
Hi everyone! I am using the script below to search a db. If the is more than one match in the db, all goes well. But if there is only one match in the db, nothing gets displayed. Any...
7
by: =?Utf-8?B?SklNLkgu?= | last post by:
How to get search engines crawl data I have a web application that uses user controls and pulls data directly from database and shows it to users in the internet. So there is not html that has the...
3
by: CF FAN | last post by:
cf search using verity for my web site. I actually took the code from docs on teh web and tweeked a couple things out on it. Now it is throwing errors and I can't figure out why. What is funny is...
0
by: jaffarkazi | last post by:
Hi I have a search page. A user would select the search parameters from various textbox, dropdowns, etc. Now the user will click search and get a list of search results. This is available in a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.