Page 1 of 1

Simple Search Query - help appreciated

Posted: Thu Jul 13, 2006 11:05 am
by mohson
Can anyone see anything wrong with this query, All im doing is searching from one table

Code: Select all

foreach($HTTP_POST_VARS as $varname => $value)
        $formVars[$varname]=$value;

	$query = 	"SELECT 
		 
		salutation,name,surname,organisation,email,address,address1,
telephonefax,mobile,mscints,mscactive,gradjobs,ugproj,pdev,bcsmem,bcspds,teach,acconsult,person_id FROM feedbackcontacts 
	
	FROM feedbackcontacts
	
	WHERE name LIKE '$formVars[name]%'";

	$result = mysql_query($query);
Previously I have used this SAME query with another table [minus some small changes] which works perfectly fine [see below]

Code: Select all

foreach($HTTP_POST_VARS as $varname => $value)
        $formVars[$varname]=$value;

$query = "SELECT 
		o.org_id,o.web_url,
		p.person_id,p.org_id,p.salutation,p.firstname,p.surname,
		p.organisation,p.role,p.address1,p.address2,p.city,
		p.postcode,p.telephone,p.mobile,p.fax,p.dateoflastcontact, 
		p.datecontactagain,p.email,p.consultation_panel_member,
		p.primary_contact,p.primarycontactemail, 
		p.advertising_grad_jobs,p.offer_mscproject,p.offer_ugproject,
		p.professional_devactivities,p.bcs_membership,p.bcs_pds,
		p.teaching_courses,p.academic_consultancy,


		DATE_FORMAT(dateoflastcontact, '%M/%Y') 
		AS dateoflastcontact, DATE_FORMAT(datecontactagain, '%M/%Y') 
		AS datecontactagain 

		
		FROM people p LEFT JOIN organisations o
     		ON o.org_id = p.org_id

		WHERE firstname LIKE '$formVars[firstname]%'";


$result = mysql_query($query);
This query works fine but the one at the top doesnt all I have changed is that Ive got rid of the date_format and the join both are no longer required?

Any help would be much appreciated.

Posted: Thu Jul 13, 2006 11:07 am
by dull1554

Code: Select all

foreach($HTTP_POST_VARS as $varname => $value)
        $formVars[$varname]=$value;

        $query =        "SELECT
                
                salutation,name,surname,organisation,email,address,address1,
telephonefax,mobile,mscints,mscactive,gradjobs,ugproj,pdev,bcsmem,bcspds,teach,acconsult,person_id FROM feedbackcontacts
        
        WHERE name LIKE '$formVars[name]%'";

        $result = mysql_query($query);
you repete FROM feedbackcontacts twice

Re: Simple Search Query - help appreciated

Posted: Thu Jul 13, 2006 11:07 am
by onion2k
mohson wrote:Can anyone see anything wrong with this query, All im doing is searching from one table

Code: Select all

foreach($HTTP_POST_VARS as $varname => $value)
        $formVars[$varname]=$value;

	$query = 	"SELECT 
		 
		salutation,name,surname,organisation,email,address,address1,
telephonefax,mobile,mscints,mscactive,gradjobs,ugproj,pdev,bcsmem,bcspds,teach,acconsult,person_id FROM feedbackcontacts 
	
	FROM feedbackcontacts
	
	WHERE name LIKE '$formVars[name]%'";

	$result = mysql_query($query);
Previously I have used this SAME query with another table [minus some small changes] which works perfectly fine [see below]
FROM feedbackcontacts is there twice.

Posted: Thu Jul 13, 2006 11:08 am
by dull1554
:) i win :-P

Posted: Thu Jul 13, 2006 11:09 am
by mohson
Why is it that the simple answers are always the best!!

Thanks guys