Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Make a PHP/MySQL search more specific
Old 09-14-2009, 01:34 PM Make a PHP/MySQL search more specific
Experienced Talker

Posts: 48
Name: Craig
Trades: 0
So, I have a moderately large database of customer names that is searchable via a PHP form. Right now it is set up with one form input to search the table.
How would I go about setting it up with two inputs, one for first name and one for last? Do I have to set up separate forms for each text input?
werm82 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-14-2009, 03:50 PM Re: Make a PHP/MySQL search more specific
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Quote:
Originally Posted by werm82 View Post
How would I go about setting it up with two inputs, one for first name and one for last?
Add another field for searching using your current methodology and update the quires.
Quote:
Originally Posted by werm82 View Post
Do I have to set up separate forms for each text input?
No.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 09-15-2009, 12:28 AM Re: Make a PHP/MySQL search more specific
Experienced Talker

Posts: 48
Name: Craig
Trades: 0
Forgive me for being naive to PHP (I'm a designer, so I took up javascript instead ) But this is what I have for my code at the moment. Would I have to change SELECT * to SELECT col_name? And would I integrate it into what I currently have now, or create another SELECT statement? I guess I know what needs to be done, but I'm having trouble translating it from English to PHP. If I'm being too dense, just say so.

PHP Code:
if (isset($_POST['last_name'])) {
  
$colname_Recordset1 $_POST['last_name'];
}
mysql_select_db($database_db$db);
$query_Recordset1 sprintf("SELECT * FROM db WHERE last_name LIKE %s"GetSQLValueString("%" $colname_Recordset1 "%""text"));
$Recordset1 mysql_query($query_Recordset1$db) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$colname_Recordset1 "-1"
werm82 is offline
Reply With Quote
View Public Profile
 
Old 09-19-2009, 12:27 PM Re: Make a PHP/MySQL search more specific
bmcoll3278's Avatar
Super Talker

Posts: 118
Name: Brian Collins
Trades: 0
In your query string you can see

where last_name LIKE %s

The rest of the string looks funny to me

But if I was doing it I would use something like

where last_name LIKE %s AND first_name LIKE %s

If that makes sense

Check out this tutorial it covers what you want to do

http://www.w3schools.com/SQl/sql_like.asp
__________________
I hope to build a site with something for every one

Please login or register to view this content. Registration is FREE
bmcoll3278 is offline
Reply With Quote
View Public Profile Visit bmcoll3278's homepage!
 
Old 09-20-2009, 08:12 PM Re: Make a PHP/MySQL search more specific
dweebsonduty's Avatar
Junior Talker

Posts: 3
Name: Shane Burgess
Trades: 0
You can use one form and do something like..

PHP Code:
$myand "";

if (
$_POST["last"])
{
$last $_POST["last"];
$myand .= " AND lastname LIKE '%$last%'";
}

if (
$_POST["city"])
{
$city $_POST["city"];
$myand .= " AND city LIKE '%$city%'";
}
$query "SELECT * FROM blah where firstname = '$first$myand"
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

dweebsonduty is offline
Reply With Quote
View Public Profile
 
Old 09-23-2009, 11:57 AM Re: Make a PHP/MySQL search more specific
Experienced Talker

Posts: 48
Name: Craig
Trades: 0
I almost got it! I tried
PHP Code:
$query_rsSearch sprintf("SELECT * FROM admins WHERE Last_Name LIKE %s AND First_Name LIKE %s"GetSQLValueString($colname_rsSearch"text")); 
But when I ran a search, I got a sprintf error,
Warning: sprintf() [function.sprintf]: Too few arguments in C:\wamp\www\admins\search.php on line 39
Query was empty
The same thing happens when I replace AND with OR. And what the hell is sprintf anyway?
werm82 is offline
Reply With Quote
View Public Profile
 
Old 09-24-2009, 07:37 PM Re: Make a PHP/MySQL search more specific
bmcoll3278's Avatar
Super Talker

Posts: 118
Name: Brian Collins
Trades: 0
You got me on that one Sorry.
__________________
I hope to build a site with something for every one

Please login or register to view this content. Registration is FREE
bmcoll3278 is offline
Reply With Quote
View Public Profile Visit bmcoll3278's homepage!
 
Old 09-24-2009, 09:10 PM Re: Make a PHP/MySQL search more specific
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
You only have the sprintf parameter for the first %s (last name), not the last %s. Add in the parameter for first name.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to Make a PHP/MySQL search more specific
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.09329 seconds with 12 queries