473,698 Members | 2,503 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MySQL searching

40 New Member
Hi all,

I'm trying to write up my first SQL database which I would want to be search able. Now currently I can have it search by First Name and Last Name. My code for the search goes like :
[PHP]$search = "SELECT *
FROM `Customer_info`
WHERE `First Name` LIKE CONVERT( _utf8 '$_POST[f_name]'
USING latin1 )
COLLATE latin1_swedish_ ci
AND `Last Name` LIKE CONVERT( _utf8 '$_POST[l_name]'
USING latin1 )
COLLATE latin1_swedish_ ci
LIMIT 0 , 30" ; [/PHP]

Now I can search only by First Name and Last Name. If I leave out either I get back blank results.

I tried searching around the net, and tried to logic it out on my own, but I just can't figure out how I can make it so that it can search by which ever field (or fields)has had information entered into it.

Can someone please guide me on how i can solve this either through PHP or SQL?

Thanks
Feb 10 '08 #1
3 1007
mwasif
802 Recognized Expert Contributor
Moved to PHP Forum.
Feb 10 '08 #2
Markus
6,050 Recognized Expert Expert
I believe you can use 'OR' for this.

[php]
$_select = "
SELECT
*
FROM
`table_name`
WHERE
`row_name`
LIKE
'{$_some_ESCAPE D_string}'
OR
`other_row_name `
=
'{$_someOther_E SCAPED_string}'
";
[/php]

I also think you should rename your table rows; replace spaces with underscores:
Expand|Select|Wrap|Line Numbers
  1. 'Row Name' = 'Row_Name'
  2.  
Also be sure to escape your POST strings to prevent mysql injection!
Feb 10 '08 #3
BOMEz
40 New Member
Thanks it works!

Thanks for reminding me about the names, I'll change em later. This is a work in progress so I'll be adding in security features later, like closing sessions, checking user input etc. For now I just need it to work to make a presentation on so I can get the green light to finish everything.
Feb 11 '08 #4

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

Similar topics

14
1819
by: Domestos | last post by:
Hi, TIA... 1) Need to select all rows from table called fixtures where home_team and away_team is equal to team_code. What SQL select statement would do this? 2) I have a variable called fixture_date in the format dd-MMM-yy (i.e. 02-Mar-05) how do I select the day/month/year into thier own variables using PHP?
51
3766
by: w_curtis | last post by:
I'm an Access user, and I'm trying to learn MySQL and then PHP so I can make some web databases. But it just isn't clicking. I've followed some tutorials, and picked up a book, but just getting to square one has been a pain. I can follow the tutorials and get to the point where I can make tables and stuff, but I don't know how I got there, or what to do if something changes that makes it different than the tutorial. MySQL doesn't seem...
4
2757
by: Michi | last post by:
I was wondering what the best solution is for making large numbers of TEXT (or BLOB?) fields searchable. For example, if I have a forum, what is the best way to be able to search for specific words? How about exact phrases? I saw a solution where all words are preindexed in a "dictionary" like table and then another table stores the word matches. That seems really fast, but it has two major problems: 1) it can't do exact matches, and 2)...
17
2895
by: chicha | last post by:
Hey people, I have to convert MS Access 2000 database into mysql database, the whole thing being part of this project I'm doing for one of my faculty classes. My professor somehow presumed I knew db's and gave me long list of things to do with that particular database, first thing being that particular conversion. Truth is that I don't know a first thing about db's, let alone using mysql... I downloaded mysql form www.mysql.com and...
7
1756
by: binary-nomad | last post by:
Hello, When I do a "AND" in a SQL query, eg. SELECT NAME WHERE SEX="male" AND AGE= "30", MySQL does a sub-search, right? i.e. it does the "WHERE SEX=male" first, and then searches through the list of *those* results to see if AGE=30? Does it do this from left to right? i.e. in the query above, would the table always, and necessarily, get searched for "SEX=male" first, and "AGE=30" second?
15
4606
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to communicate with a MySQL database table on a web server, from inside of my company's Access-VBA application. I know VBA pretty well but have never before needed to do this HTTP/XML/MySQL type functions.
2
1442
by: Richard Brosnahan | last post by:
I hate asking questions that have probably been answered before, but I have not found a way to conveniently search the archives of this mailing list. So... Can someone tell me how to search this mailing list, short of downloading every month's archive and searching manually? Or, can someone tell me how to easily interface with MySQL with
4
1718
by: | last post by:
Hello... i have a table which contains a column named "ask" and a column named "per"... my think is that i want to search in "ask" and echo the data stored in "per" for this entry... How do i do this? Thanx in advance! JBK
4
1604
by: Robertu | last post by:
Scusatemi ma le pagine di visualizzazione dei dati dal mio database mysql funziona bene tranne quando voglio selezionare meglio i dati della query per visualizzare solo i records che risposndano ad una determinato filtro Per esempio io voglio impostare il filtro sul campo "TIPO" e selezionare solo quei records che contengono la fease "di feltro a righe rosse" Se faccio $query = "SELECT nome, colore, memo FROM archivio where tipo='di feltro...
1
3011
by: Steve Ametjan | last post by:
I've been trying to get MySQL-python to install on Leopard for the past couple of days, and I keep running into relatively the same error. I'm hoping that someone on this list will be able to help me out in solving the issue. I'd like to get this solved so I can continue developing with Django using MySQL since that's what my web server uses as well. I'd hate to have to develop using a different database engine on my local...
0
8680
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9030
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.