Jump to content


Photo

multifield form search


  • Please log in to reply
29 replies to this topic

#21 olm75

olm75
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 13 August 2005 - 06:06 PM

is this !@#$ really this hard or what, come on y aint this !@#$ working can anybody help im getting to !@#$ frustrated....all i want to do is make a search page with different search fields that narrow down a search to a viewer....!@#$
has anbody on here ever made a search page with more thatn 1 field.....

#22 olm75

olm75
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 13 August 2005 - 06:08 PM

what would $CRT be



The things are not quite so complicated! Try smth like that:

$QueryString = "SELECT * FROM table_name ";

if (isset($_POST['your_form_field'])) {
  $Crt = $_POST['your_form_field'];
  $QueryString .= " WHERE table_field LIKE %\"$Crt\"%";
}

You use such "if" statements for all your search criterias, to build up a dynamic SQL Query.

After you finished, try to run the query.

Enjoy

View Post



#23 jvrothjr

jvrothjr
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts
  • LocationOhio

Posted 15 August 2005 - 01:58 PM

[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]
$VN = $_POST[venuename];
$AC = $_POST[areacode];
$AG = $_POST[agegroup];

//-----HOW DO I ADD THESE TO VARIBLES TO THE QUERY FROM MY SEARCH FORM---------
$VT = $_POST[venuetype];
$MT = $_POST[musictype]; [/span][!--PHP-Foot--][/div][!--PHP-EFoot--]

Are your values passing.

have you checked that????????????????????????????????

if the query returns no records found.

Echo the variables to the screen just to see it the values are right to what you think they should be.

And no it is not hard if things are passed right.



If you understand everything you know nothing!

http://rcchjr.awardspace.com/

#24 olm75

olm75
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 19 August 2005 - 08:09 AM

venuename is the database column
txtVenuename is the form_field
$VT = $_POST['txtVenuename']

so it should look like this:
[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]
[span style=\"color:#0000BB\"]<?php
$VN [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#0000BB\"]venuename[/span][span style=\"color:#007700\"]];
[/span][span style=\"color:#0000BB\"]$AC [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#0000BB\"]areacode[/span][span style=\"color:#007700\"]];
[/span][span style=\"color:#0000BB\"]$AG [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#0000BB\"]agegroup[/span][span style=\"color:#007700\"]];

[/span][span style=\"color:#FF8000\"]//-----HOW DO I ADD THESE TO VARIBLES TO THE QUERY FROM MY SEARCH FORM---------
[/span][span style=\"color:#0000BB\"]$VT [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#0000BB\"]venuetype[/span][span style=\"color:#007700\"]];
[/span][span style=\"color:#0000BB\"]$MT [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#0000BB\"]musictype[/span][span style=\"color:#007700\"]];
[/span][span style=\"color:#FF8000\"]//-----------------------------------------------------


[/span][span style=\"color:#0000BB\"]$mysql_mylink [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]mysql_pconnect[/span][span style=\"color:#007700\"]([/span][span style=\"color:#DD0000\"]\"localhost\"[/span][span style=\"color:#007700\"], [/span][span style=\"color:#DD0000\"]\"nightsp\"[/span][span style=\"color:#007700\"], [/span][span style=\"color:#DD0000\"]\"babystuff\"[/span][span style=\"color:#007700\"]) or die([/span][span style=\"color:#0000BB\"]mysql_error[/span][span style=\"color:#007700\"]());
[/span][span style=\"color:#0000BB\"]mysql_select_db [/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]nightsp_nightspotz[/span][span style=\"color:#007700\"]) or die([/span][span style=\"color:#0000BB\"]mysql_error[/span][span style=\"color:#007700\"]());
echo [/span][span style=\"color:#DD0000\"]\"<TABLE class=\'sortable\' id=\'Identify\' BORDER=1 align=center>\"[/span][span style=\"color:#007700\"];
echo [/span][span style=\"color:#DD0000\"]\"<TD>VENUENAME</TD><TD>AREACODE</TD><TD>AGE GROUP</TD><TD>CITY</TD><TD>STATE</TD>\"[/span][span style=\"color:#007700\"];
[/span][span style=\"color:#0000BB\"]$querystring [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"SELECT * FROM venues_new\"[/span][span style=\"color:#007700\"];

if (isset([/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'txtVenuename\'[/span][span style=\"color:#007700\"]])) {
[/span][span style=\"color:#0000BB\"]$VN [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'txtVenuename\'[/span][span style=\"color:#007700\"]];
[/span][span style=\"color:#0000BB\"]$querystring [/span][span style=\"color:#007700\"].= [/span][span style=\"color:#DD0000\"]\" WHERE venuename LIKE %\\"[/span][span style=\"color:#0000BB\"]$VT[/span][span style=\"color:#007700\"]&[/span][span style=\"color:#FF8000\"]#092;\"%\";
[/span][span style=\"color:#007700\"]}

[/span][span style=\"color:#0000BB\"]$SearchMatch [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]mysql_query [/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$querystring[/span][span style=\"color:#007700\"], [/span][span style=\"color:#0000BB\"]$mysql_mylink[/span][span style=\"color:#007700\"]) or die([/span][span style=\"color:#0000BB\"]mysql_error[/span][span style=\"color:#007700\"]());
if ([/span][span style=\"color:#0000BB\"]$MatchRecordRow [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]mysql_fetch_array[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$SearchMatch[/span][span style=\"color:#007700\"])) {
   do{
      echo [/span][span style=\"color:#DD0000\"]\"<TR><td>\"[/span][span style=\"color:#007700\"].[/span][span style=\"color:#0000BB\"]$MatchRecordRow[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'venuename\'[/span][span style=\"color:#007700\"]].[/span][span style=\"color:#DD0000\"]\"</TD>\"[/span][span style=\"color:#007700\"];
      echo [/span][span style=\"color:#DD0000\"]\"<td>\"[/span][span style=\"color:#007700\"].[/span][span style=\"color:#0000BB\"]$MatchRecordRow[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'areacode\'[/span][span style=\"color:#007700\"]].[/span][span style=\"color:#DD0000\"]\"</TD><td>\"[/span][span style=\"color:#007700\"].[/span][span style=\"color:#0000BB\"]$MatchRecordRow[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'agegroup\'[/span][span style=\"color:#007700\"]].[/span][span style=\"color:#DD0000\"]\"</TD>\"[/span][span style=\"color:#007700\"];
      echo [/span][span style=\"color:#DD0000\"]\"<td>\"[/span][span style=\"color:#007700\"].[/span][span style=\"color:#0000BB\"]$MatchRecordRow[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'city\'[/span][span style=\"color:#007700\"]].[/span][span style=\"color:#DD0000\"]\"</TD><td>\"[/span][span style=\"color:#007700\"].[/span][span style=\"color:#0000BB\"]$MatchRecordRow[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'state\'[/span][span style=\"color:#007700\"]].[/span][span style=\"color:#DD0000\"]\"</TD>\"[/span][span style=\"color:#007700\"];
} while([/span][span style=\"color:#0000BB\"]$MatchRecordRow [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]mysql_fetch_array[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$SearchMatch[/span][span style=\"color:#007700\"]));
} else {echo [/span][span style=\"color:#DD0000\"]\"<center>Sorry, No Records Were Found!</center>\"[/span][span style=\"color:#007700\"];}
echo [/span][span style=\"color:#DD0000\"]\"</table>\"[/span][span style=\"color:#007700\"];
[/span][span style=\"color:#0000BB\"]mysql_free_result[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$SearchMatch[/span][span style=\"color:#007700\"]);

[/span][span style=\"color:#0000BB\"]?>
[/span]
[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]

#25 olm75

olm75
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 19 August 2005 - 08:21 AM

i get this error:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '%""%' at line 1

#26 jvrothjr

jvrothjr
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts
  • LocationOhio

Posted 19 August 2005 - 12:05 PM

$querystring .= " WHERE venuename LIKE '%$VT%'";

This will find any field the contains this value
If you understand everything you know nothing!

http://rcchjr.awardspace.com/

#27 olm75

olm75
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 24 August 2005 - 08:36 AM

y is my query not bringing results....not found...i want the viewers to search using 1 or any combination of fields.....


[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]
$querystring = \"select * from venues\";
if ($VN != \"\" AND $AC == \"\" AND $AG == \"\") {$querystring .=  \" where (venuename like \'%$VN%\')\";}
if ($VN != \"\" AND $AC != \"\" AND $AG == \"\") {$querystring .=  \" where (venuename like \'%$VN%\') AND (areacode like \'%$AC%\')\";}
if ($VN != \"\" AND $AC == \"\" AND $AG != \"\") {$querystring .=  \" where (venuename like \'%$VN%\') AND (agegroup like \'%$AG%\')\";}
if ($VN == \"\" AND $AC != \"\" AND $AG == \"\") {$querystring .=  \" where (areacode like \'%$AC%\')\";}
if ($VN == \"\" AND $AC != \"\" AND $AG != \"\") {$querystring .=  \" where (areacode like \'%$AC%\') AND (agegroup like \'%$AG%\')\";}
if ($VN == \"\" AND $AC == \"\" AND $AG != \"\") {$querystring .=  \" where (agegroup like \'%$AG%\')\";}
if ($VN == \"\" AND $AC == \"\" AND $AG == \"\") {}
[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]

#28 jvrothjr

jvrothjr
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts
  • LocationOhio

Posted 24 August 2005 - 12:24 PM

[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]$querystring = \"select * from venues\";
if ($VN != \"\" AND $AC == \"\" AND $AG == \"\") {$querystring =  $querystring + \" where (venuename like \'%$VN%\')\";}[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]
If you understand everything you know nothing!

http://rcchjr.awardspace.com/

#29 olm75

olm75
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 27 August 2005 - 01:19 AM

ok thanks, but
do i just do that for all of the if statements or just that 1st one....

#30 jvrothjr

jvrothjr
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts
  • LocationOhio

Posted 29 August 2005 - 12:20 PM

ok thanks, but
do i just do that for all of the if statements or just that 1st one....

View Post


All

If you understand everything you know nothing!

http://rcchjr.awardspace.com/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users