d-lexy Posted March 20, 2007 Share Posted March 20, 2007 Hi There! I'm writing a very basic search script. I have a form field where I want to accept both first and last names. In my database, the first and last names are in separate fields. I want the query to go through both fields and come up with results. Here is the PHP code so far (only searches first name): $search = $_POST['search']; $data = mysql_query("SELECT * FROM customers WHERE fname LIKE'%$search%'"); //Display results while($result = mysql_fetch_array($data)) { echo $result['fname']; echo " "; echo $result['lname']; echo "<br>"; } How can i change this around to perform the way I need? Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/43551-solved-mysql_query-select-from-multiple-fields/ Share on other sites More sharing options...
genericnumber1 Posted March 20, 2007 Share Posted March 20, 2007 it's... SELECT * FROM customers WHERE fname LIKE '%$search%' OR lname LIKE '%$search%' sorry about the mixup, dunno what I was thinking Link to comment https://forums.phpfreaks.com/topic/43551-solved-mysql_query-select-from-multiple-fields/#findComment-211490 Share on other sites More sharing options...
d-lexy Posted March 20, 2007 Author Share Posted March 20, 2007 So simple! Thank you so much! Link to comment https://forums.phpfreaks.com/topic/43551-solved-mysql_query-select-from-multiple-fields/#findComment-211500 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.