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

MySQL searching

40
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 999
mwasif
802 Expert 512MB
Moved to PHP Forum.
Feb 10 '08 #2
Markus
6,050 Expert 4TB
I believe you can use 'OR' for this.

[php]
$_select = "
SELECT
*
FROM
`table_name`
WHERE
`row_name`
LIKE
'{$_some_ESCAPED_string}'
OR
`other_row_name`
=
'{$_someOther_ESCAPED_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
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
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...
51
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...
4
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...
17
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...
7
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...
15
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...
2
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...
4
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...
4
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.