Re: [PHP-DB] search form w/ multiple fields
since: ?php echo $_POST['firstname']; ? does not work on your installation, try: ?php echo $GLOBALS['HTTP_POST_VARS']['firstname']; ? when the form is submitted. there is an obvious oversight in the SQL query below. You are currently checking whether or not the firstname, lastname, phone or email data from the form is present in only the firstname field. also, an elegant solution would be to build the SQL query based on which form fields have been populated. Vincent Jordan wrote: I have a form with firstname, lastname, phone, and email fields. I would like to search the database and return results to the same page in an iframe. I want to be able to search my just one or multiple. For example I can search by firstname with value of john and it will return all john rows in iframe or search firstname value john and lastname value smith and again will return all rows with data in iframe. I have tried this but don't think I am doing something correct: $result = mysql_query (select * from customerinfo where firstname like '%.$_POST['firstname'].%' or '%.$_POST['lastname'].%' or '%.$_POST['phone'].%' or '%.$_POST['email'].%'); I cant seem to figure out how to display. I have tried ?php echo $_POST['firstname']; ? in the HTML but there was no return of data. This is my form: form action=search.php method=post name=search id=search First Name: input type=text name=firstname / Last Name: input type=text name=lastname / Phone : input type=text name=phone / Email : input type=text name=email / input type=submit value=search /form all of this is on the same page, the page is called search.php -- _ Matthew McNicol yellowmarker.co.uk PHP / MySQL web development -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Query returns duplicate rows
On Thu, 22 Jul 2004 05:59, Brock Jimmy D Contr 74 Mdss/Sgsi wrote: My query is returning duplicates rows. table: elements elementId standardId elementtext category mcode linenum table: scores scoreId taskId scores Here's my query: SELECT distinct elementtext,cateogy,mcode,linenum,scores,scoreId FROM elements, scores WHERE scores.taskId='12' AND elements.standardId='APR.05' This is returning duplicate rows, even though I'm using the DISTINCT keyword. If I remove the field scoreId it is fine. Any suggestions? I think you may misunderstand exactly what DISTINCT does. The keyword applies to the entire record, not individal fields, and will effectively delete any duplicate rows. ScoreId is presumably a unique ID for the record; that being the case you can expect all selected rows will be different. Cheers -- David Robley Backups? We don' *NEED* no steenking backups. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] FULLTEXT and LIKE
Hi, My head is swimming with lots of info gleaned from various newsgroups about using fulltext indexes in MySQL, but, I'm still not sure what the best solution would be for what I want to do. I'm concerned about the 3-char minimum and not being able to search on partial words (my version of MySQL doesn't support boolean fulltext searches). I have a simple News table that is structured like this: CREATE TABLE `news` ( `id` int(7) unsigned NOT NULL auto_increment, `author` varchar(50) NOT NULL default '', `headline` varchar(60) NOT NULL default '', `content` text NOT NULL, `url` text NOT NULL, UNIQUE KEY `id` (`id`), ) TYPE=MyISAM; I want searches for News to be on the author, headline and content fields. What is the best way to index and search this? A) Create a combined fulltext index: FULLTEXT (author,headline,content) -- and do searches using MATCH() and AGAINST(). B) Create a fulltext index only for the content field and use this kind of select: SELECT * FROM db WHERE author LIKE %phrase% OR headline LIKE %phrase% OR MATCH(content) AGAINST(phrase); C) None of the above ... is there a better way? Thanks a lot for any input or feedback! I'm completely lost! Monty -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] FULLTEXT and LIKE
Well, like will do a full table scan if it starts with a wildcard, so you dont want to do it that way. I'd do full text search. http://dev.mysql.com/doc/mysql/en/MySQL_indexes.html -Jeff - Original Message - From: Monty [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, July 22, 2004 12:57 PM Subject: [PHP-DB] FULLTEXT and LIKE Hi, My head is swimming with lots of info gleaned from various newsgroups about using fulltext indexes in MySQL, but, I'm still not sure what the best solution would be for what I want to do. I'm concerned about the 3-char minimum and not being able to search on partial words (my version of MySQL doesn't support boolean fulltext searches). I have a simple News table that is structured like this: CREATE TABLE `news` ( `id` int(7) unsigned NOT NULL auto_increment, `author` varchar(50) NOT NULL default '', `headline` varchar(60) NOT NULL default '', `content` text NOT NULL, `url` text NOT NULL, UNIQUE KEY `id` (`id`), ) TYPE=MyISAM; I want searches for News to be on the author, headline and content fields. What is the best way to index and search this? A) Create a combined fulltext index: FULLTEXT (author,headline,content) -- and do searches using MATCH() and AGAINST(). B) Create a fulltext index only for the content field and use this kind of select: SELECT * FROM db WHERE author LIKE %phrase% OR headline LIKE %phrase% OR MATCH(content) AGAINST(phrase); C) None of the above ... is there a better way? Thanks a lot for any input or feedback! I'm completely lost! Monty -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] What's wrong with this QUERY??
Hi, I have a database with members details and PK is id. $thing = [EMAIL PROTECTED]; $query = SELECT id, email, familyname FROM members WHERE email=$thing; $result = mysql_query($query); If i do a query where id=$thing. and $thing=20; this works fine and I get the desired result. But what is wrong with the other one, when I do search for the email address?? The email address does exist exactly as quoted above in the email field in my members table but still doesn't produce any results. Any help is much appreciated. Harmeet -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] What's wrong with this QUERY??
$thing = [EMAIL PROTECTED]; $query = SELECT id, email, familyname FROM members WHERE email=$thing; You need to quote non-numeric values in SQL. It should be $query = SELECT id, email, familyname FROM members WHERE email=''$thing'; Also, you don't really need to select the email value since you should already have it. Larry -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] What's wrong with this QUERY??
--- Harry G [EMAIL PROTECTED] wrote: Hi, I have a database with members details and PK is id. $thing = [EMAIL PROTECTED]; $query = SELECT id, email, familyname FROM members WHERE email=$thing; Make it $query = SELECT id, email, familyname FROM members WHERE email='$thing'; It should work zareef ahmed $result = mysql_query($query); If i do a query where id=$thing. and $thing=20; this works fine and I get the desired result. But what is wrong with the other one, when I do search for the email address?? The email address does exist exactly as quoted above in the email field in my members table but still doesn't produce any results. Any help is much appreciated. Harmeet -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php = Zareef Ahmed :: A PHP Developer in Delhi(India). Homepage :: http://www.zasaifi.com __ Do you Yahoo!? Vote for the stars of Yahoo!'s next ad campaign! http://advision.webevents.yahoo.com/yahoo/votelifeengine/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] What's wrong with this QUERY??
On Friday 23 July 2004 10:57, Harry G wrote: I have a database with members details and PK is id. $thing = [EMAIL PROTECTED]; $query = SELECT id, email, familyname FROM members WHERE email=$thing; $query = SELECT id, email, familyname FROM members WHERE email='$thing'; Please refer to some SQL primer to learn the basics of SQL. $result = mysql_query($query); Look at the examples in the manual to see how you can incorporate error checking into your code. In particular look at mysql_error(). If i do a query where id=$thing. and $thing=20; this works fine and I get the desired result. But what is wrong with the other one, when I do search for the email address?? Because your 'id' column is numeric and 'email' column is text. Text columns needs their values enclosed by quotes. The email address does exist exactly as quoted above in the email field in my members table but still doesn't produce any results. mysql_error() would let you know that there was an error in your query. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-db -- /* I don't wish to appear overly inquisitive, but are you still alive? */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: What's wrong with this QUERY?? - Thanks all.
Thank you everybody. Harry G [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi, I have a database with members details and PK is id. $thing = [EMAIL PROTECTED]; $query = SELECT id, email, familyname FROM members WHERE email=$thing; $result = mysql_query($query); If i do a query where id=$thing. and $thing=20; this works fine and I get the desired result. But what is wrong with the other one, when I do search for the email address?? The email address does exist exactly as quoted above in the email field in my members table but still doesn't produce any results. Any help is much appreciated. Harmeet -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php