473,386 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem in search from database

Hi,
I have made a search page in which the user enters the keywords to be searched separated with a comma. The code that i ve used works well but it is displaying the name of the user twice.
Eample: There are users registered in the database. Now if
A: C,Perl,Python
B:Java,Perl
For eg: now the user has entered Perl,Python as the keywords.
Then it displays the name A twice and B once.
I wanted that it should display both the name just once.
I have used the following code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $searches = $_SESSION['search'];
  3. //Explode into seperate keywords and make all unique
  4. $terms = array_unique(explode(',',$searches));
  5. //Loop through all terms, and add text for query
  6. foreach($terms as $k=>$v)
  7. {
  8.     //Check for empty values
  9.     if($v=="") continue;
  10.     $terms[$k]="`TagName` LIKE '%$v%'";
  11. }
  12.  
  13. //Implode each term back together with the OR in between them
  14. $newsearch = implode(' OR ', $terms);
  15.  
  16. //Append to query string
  17. $query1 = mysql_query("SELECT TagId FROM tagmaster WHERE ".$newsearch."");
  18. while($nt=mysql_fetch_array($query1)){
  19. $query2 = mysql_query("SELECT DISTINCT UserName FROM usertags WHERE TagId = '$nt[TagId]'");  
  20. while($nt1=mysql_fetch_array($query2)){
  21. echo "{$nt1[UserName]}";
  22. $result = "SELECT FullName,YearsExp FROM userdetails WHERE UserName = '$nt1[UserName]'";
  23. $data = mysql_query($result) or die(mysql_error());
  24. $resultnum = mysql_num_rows($data); 
  25. if($resultnum>0) { // Echos out matches if anything was found 
  26. while($info = mysql_fetch_array($data)){ 
  27. ?>
  28.       <tr>
  29.         <td width="139" valign="top"><p align="center"><a href="searchaccount.php?id=<? echo $info['FullName']; ?>" target=\"_blank\"><? echo $info['FullName']; ?></a></p></td>
  30.         <td width="149" valign="top"><p align="center"><? echo $info['YearsExp']; ?></p></td>
  31.       </tr>
  32. }
  33.  
Structure of tables is something like this:

tagmaster
4 C
5 Java
6 Perl
7 Python

usertags
4 A
6 A
7 A
5 B
6 B

userdetails
A Alvin
B Babin
Can you plz tel me what can be possibly wrong in it. I tried using DISTINCT with fullname also but it still dint worked out.
Mar 28 '08 #1
2 1398
My problem has got solved.
I tried using joins and it worked well.
Sorry and thanks.
Mar 28 '08 #2
ronverdonk
4,258 Expert 4TB
My problem has got solved.
I tried using joins and it worked well.
Sorry and thanks.
It's good that you worked it out yourself. See you next time.

Ronald
Mar 28 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Chris H | last post by:
Ok in the following code I am trying to have my keywards meta tag auto insert the top 10 titles from most recently added database entries, right now the while loop is only setting the $keyword...
2
by: Arsalan Ahmad | last post by:
Hi, May be I am a newbie, or may be i dont have that much insight in following systems ..i.e. why i have some confusions as below: In many websites, when search is performed on some keywords...
0
by: nineeshk | last post by:
I have a search query from my MSSQL database. My problem is when i search the database using the text string which contains any umlaut character. FOr eg. When i search for Cömlek. It gives the...
3
by: Richard S | last post by:
CODE: ASP.NET with C# DATABASE: ACCES alright, im having a problem, probably a small thing, but i cant figure out, nor find it in any other post, or on the internet realy (probably cuz i wouldnt...
1
by: thepresidentis | last post by:
here is my problem, i have a website that compiles concert listings for users to search for shows in their local area, i ran into a problem with returning search results due to an improper format...
0
by: thepresidentis | last post by:
here is my problem, i have a website that compiles concert listings for users to search for shows in their local area, i ran into a problem with returning search results due to an improper format...
6
by: jej1216 | last post by:
I am trying to put together a PHP search page in which the user can select none, one, two, or three fields to search, and then the results php will build the SQL with dynamic where caluses to reflect...
1
by: russot00 | last post by:
I have 3 drop down menus that are used in a search to locate restaurants in a db. All of the drop down menus function, a search can be submitted with any combination of drop downs and the results are...
2
by: dmstn | last post by:
Hey! I've got a little problem. I have to make a web site for a university essay. I curently have to create a search engine. Users can enter a hotel name in a search bar and results have to appear in...
20
tdw
by: tdw | last post by:
Hi all, I have an "Address" field that, upon an After Update event, searches the database to see if the address I just entered already exists in the database. This search used to only take a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.