473,385 Members | 1,356 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,385 software developers and data experts.

Searching for a name in a database when I only know part of the name

I want to know the php code to make an telephone diary..i mean exactly
.,suppose the in database the name stored is " Manoj mishra ",but in the form by typing only"manoj" we can see the details of manoj mishra..how could we do it..?pls giv an example for clear understanding..
Oct 13 '07 #1
6 1250
debasisdas
8,127 Expert 4TB
Question moved to PHP forum.
Oct 13 '07 #2
Markus
6,050 Expert 4TB
I want to know the php code to make an telephone diary..i mean exactly
.,suppose the in database the name stored is " Manoj mishra ",but in the form by typing only"manoj" we can see the details of manoj mishra..how could we do it..?pls giv an example for clear understanding..
What database?

MySQL?
Oct 13 '07 #3
Markus
6,050 Expert 4TB
I want to know the php code to make an telephone diary..i mean exactly
.,suppose the in database the name stored is " Manoj mishra ",but in the form by typing only"manoj" we can see the details of manoj mishra..how could we do it..?pls giv an example for clear understanding..
Supposing you're using MySQL

Try something like this

Expand|Select|Wrap|Line Numbers
  1. $name = $_POST['name']; //from a form the user filled in?
  2.  
  3. $query = "SELECT * from `insert your table name` WHERE `table cell you want to check` like '%$name'"; 
  4. /*this selects everything from the table you want where user input is something like a name you pulled out of table
  5.  
  6. The % is a wildcard - that means it'll pull soemthing that's like what you want in relation to where you put the %
  7.  
  8. e.g. mark % would get: mark skilbeck, mark jameson etc. % mark would get: john mark, chris mark etc. % mark % would (i think) get: something mark something etc. You get the picture :)*/
  9.  
  10. $checkQuery = mysql_query($query); //run a mysql_query
  11.  
  12. $numRows = mysql_numrows($checkQuery); /*gets numbers of rows from table where data in $query is true*/
  13.  
  14. echo "
  15. <table>
  16.  <tr><th>name</th><th>age</th><th>email</th></tr>";
  17. if($numRows => 1){ // if number of rows is equal-to or greater-than: run script
  18.  while($row = mysql_fetch_array($query)){
  19. /* will keep fetching data until it returns false (reaches end) */
  20.   echo "<tr><td>$row['name']</td><td>$row['age']</td><td>$row['email']</td></tr>";
  21.  }
  22. } else {
  23. echo "<tr><td colspan=\"3\">Your search returned no results</td></tr>";
  24. }
  25. echo "</table>";
  26. /*the bit above creates a table. The $row is what you will use to access your data in the MySQL table. Just change the ['name'] etc. to reflect the names of the cells in your MySQL table.*/
  27.  
That should work but i haven't tested it and i am only 17 and i had a heavy night last night.

Less of the excuses - hope this helped :)
Oct 13 '07 #4
Markus
6,050 Expert 4TB
I'm going to test it ¬_¬
Oct 13 '07 #5
Markus
6,050 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. $name = $_GET['name']; //from a form the user filled in?
  2.  
  3. $query = "SELECT * from `example` WHERE `name` like '%$name'"; 
  4. /*this selects everything from the table you want where user input is something like a name you pulled out of table
  5.  
  6. The % is a wildcard - that means it'll pull soemthing that's like what you want in relation to where you put the %
  7.  
  8. e.g. mark % would get: mark skilbeck, mark jameson etc. % mark would get: john mark, chris mark etc. % mark % would (i think) 
  9.  
  10. get: something mark something etc. You get the picture :)*/
  11.  
  12. $checkQuery = mysql_query($query); //run a mysql_query
  13.  
  14. $numRows = mysql_numrows($checkQuery); //gets numbers of rows from table where data in $query is true
  15. ?>
  16. <table><tr><th>name</th><th>age</th><th>email</th></tr>
  17. <?php
  18. if($numRows >= 1){ // if number of rows is equal-to or greater-than: run script
  19.  while($row = mysql_fetch_array($checkQuery)){
  20. /* will keep fetching data until it returns false (reaches end) */
  21.   echo "<tr><td>".$row['name']."</td><td>".$row['email']."</td><td>".$row['age']."</td></tr>";
  22.  }
  23. } else {
  24. echo "<tr><td colspan=\"3\">Your search returned no results</td></tr>";
  25. }
  26. echo "</table>";
  27. /*the bit above creates a table. The $row is what you will use to access your data in the MySQL table. Just change the 
  28.  
  29. ['name'] etc. to reflect the names of the cells in your MySQL table.*/
  30. ?>
  31.  
There was a few typos in there ;)

But it works just fine :)
Oct 13 '07 #6
pbmods
5,821 Expert 4TB
Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).
Oct 13 '07 #7

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

Similar topics

2
by: John | last post by:
Hi everyone ! This is a first time I post a message here. If I post my message in a wrong group. Please ignore it. I am trying to build a website which allows users (can be thousands of...
5
by: ebernedo | last post by:
Hey guys, I'm new here and also pretty new to access I'm creating a database at work, and need to be able to search things within it to find the right part number in our case... heres a sample...
2
by: napsters | last post by:
Hello...I want to make something in VB (Version 9) that reads multiple data from specified file (Access 2007) and displays content in list box. If file doesn't exist, alert user. More...
12
by: Alexnb | last post by:
This is similar to my last post, but a little different. Here is what I would like to do. Lets say I have a text file. The contents look like this, only there is A LOT of the same thing. () A...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.