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!

Printing the results instead of the query!!!

Status
Not open for further replies.

Kinob

Programmer
May 8, 2002
4
NL
Hi everybody!,

Once again Kinob is back, I still have probs with my checkbox searchengine, but I’m getting closer by the day. I just need to keep tryin’ and ask you guys for help. This time, the script just prints out the query. So if my query is:

**************** Query ****************

SELECT DISTINCT members.membername FROM members INNER JOIN lookup_skills ON members.id=lookup_skills.uid INNER JOIN const_skills ON lookup_skills.skill_id=const_skills.id WHERE const_skills.id(1) ORDER BY members.membername

**************************************

I just get this on my screen:

**************** Screen ****************

SELECT DISTINCT members.membername FROM members INNER JOIN lookup_skills ON members.id=lookup_skills.uid INNER JOIN const_skills ON lookup_skills.skill_id=const_skills.id WHERE const_skills.id(1) ORDER BY members.membername
MySQL error:

*****************************************

I just want to view the members that know the checked scripting language. Could someone please help me with printing the results, thnx (see below for the files and SQL tables)

*****************************************
*****************************************
**************** 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;>cgi</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&quot;>HTML</tr>
<tr></table>
<br>
<input type=&quot;submit&quot; value=&quot;Submit&quot;>
</form>
</body>
</html>

**************** search.php ****************

<?php

if(!empty($_POST['skills'])){



$dbcnx = @mysql_connect(
&quot;localhost&quot;, &quot;lucasman&quot;, &quot;cgimaster&quot;);
if (!$dbcnx) {
echo( &quot;<P>Unable to connect to the &quot; .
&quot;database server at this time.</P>&quot; );
exit();
}


if (! @mysql_select_db(&quot;checksearch&quot;) ) {
echo( &quot;<P>Unable to locate the database at this time.</P>&quot; );
exit();
}
$num_skills=sizeof($_POST['skills']);
$query='SELECT DISTINCT members.membername FROM members INNER JOIN lookup_skills ON members.id=lookup_skills.uid'
.'INNER JOIN const_skills ON lookup_skills.skill_id=const_skills.id WHERE const_skills.id IN(';
$query.=join(',',$_POST['skills']);
$query.=') ORDER BY members.membername';
echo $query . '<br>';



$result=@mysql_query($query,$con)or die('Error in query: '.mysql_error());

$numrows=@mysql_num_rows($result);

if($numrows!=0){



while($row=mysql_fetch_assoc($result)){

echo$row['membername'].'<br>';

}



}else{



echo'Sorry, but no matches were found...<br>';



}



}else{



echo'You DO want to see some skills, don'tyou?<br>';

}

?>

**************** SQL: const_skills ****************

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

**************** SQL: 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

**************** SQL: members ****************

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

Hope somebody can help me....

Kinob

 
Do you have your query in the php tags?

<? query goes here ?>

If you don't it will print ot the screen.


MAO
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top