Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP checkbox search engine??

Status
Not open for further replies.

bobo2003

Technical User
Sep 10, 2005
3
US
Hi,
I’m pretty new to PHP and MySQL and I wanted to create a search engine with checkboxes. In my database are names of our programmers and what programming languages they can write.

I got one (.html) form and one (.php) file that searches the database. Every time I try to connect to the database, I get a blank page?! Could someone help me, I don’t know what’s wrong. Below you can find the tables and files.

Search.php:

<?php

$db_name = &quot;checksearch&quot;;
$connection = @mysql_connect(&quot;localhost&quot;, &quot;Bobo&quot;, &quot;password_doesnt_matter&quot;) or die(&quot;couldn't connect&quot;);
$db = @mysql_select_db($db_name, $connection) or die(&quot;Couldn't select db&quot;);


/* builds a query to search for the skills
checked off in the $skills array */

function skill_search($skills) {
if (!empty($skills)) {
$query = &quot;SELECT DISTINCT members.membername
FROM members, const_skills, lookup_skills
WHERE lookup_skills.uid = user.id
AND lookup_skills.skill_id = const_skills.id &quot;;

$query .= &quot; AND (&quot;;
foreach ($skills as $check) {
$query .= &quot; const_skills.id = $check OR&quot;;
}

/* remove the final OR */
$query = substr($query, 0, -2);
$query .= &quot;)&quot;;

$count = count($skills);
$query .= &quot; GROUP BY members.membername HAVING count(members.membername) >= $count&quot;;

$query .= &quot;;&quot;;
return $query;
}
}

?>

form.html:

HTML:
[body]
[br]
[form name=&quot;skills&quot; method=&quot;POST&quot; action=&quot;search.php&quot;]
   Check off your web development skills:
   [table width=&quot;400&quot; border=&quot;0&quot;]
[tr]
[td][input type=&quot;checkbox&quot; name=&quot;skills[]&quot; value=&quot;1&quot;]PHP[/td]
[td][input type=&quot;checkbox&quot; name=&quot;skills[]&quot; value=&quot;2&quot;]ASP[/td]
[td][input type=&quot;checkbox&quot; name=&quot;skills[]&quot; value=&quot;3&quot;]Perl[/td][/tr]
[tr][td][input type=&quot;checkbox&quot; name=&quot;skills[]&quot; value=&quot;4&quot;]JavaScript[/td]
[td][input type=&quot;checkbox&quot; name=&quot;skills[]&quot; value=&quot;5&quot;]JSP[/td]
[td][input type=&quot;checkbox&quot; name=&quot;skills[]&quot; value=&quot;6]Coldfusion[/tr]
[tr][/table]
   [br]
   [input type=&quot;submit&quot; value=&quot;Submit&quot;]
[/form]
[/body]

SQL tables:

const_skills:

id: value:
1 PHP
2 ASP
3 Perl
4 JavaScript
5 JSP
6 Coldfusion

lookup_skills:

id: uid: skill_id:
1 1 1
2 1 3
3 1 4
4 1 6
5 2 1
6 2 4
7 2 6
8 3 1
9 3 3
10 3 4
11 3 5
12 3 6
13 4 2

members:

id: membername:
1 John
2 Dan
3 Bob
4 Robin

Could somebody please help, that would be great!,

Bobo

P.S. the &quot;<&quot; and &quot;>&quot; were replaced by the &quot;[&quot; and &quot;]&quot;, it's not a mistake! hehehe
 
where do you execute the query?
where do you call the function? Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top