i want to search the database mysql and i want to find similar links

Posted on 2008-10-13
Last Modified: 2008-10-25
lets say i have this links in the database

and i want to search for all the links that look like
want the command to output

and not
i know this command the like command but its not working as u want
Question by:mgtm3
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4

Expert Comment

by:Sander Stad
ID: 22708884
In deed you need the "LIKE" command to get those values. Can you show me the query you originally created that doesn't work?

Author Comment

ID: 22710456
     $query = "    SELECT * FROM ddd WHERE d_link LIKE '%$link%'; ";

Author Comment

ID: 22713871
soo anyone?
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

by:Sander Stad
ID: 22715134
Because you want to search for links in a database that start with a certain string you'd like to split the string before searching for it.
The code below creates an array with all the pieces of the url split by the "/". Than a query is set up to get all the needed results. After that the results are displayed.

$link = "";
$pieces = explode("/", $link);
$query = "SELECT * FROM {tablename} WHERE {column} LIKE \"%$pieces[0]%\";";
$results = mysql_query($query);
while($row = mysql_fetch_array($results)){
  echo "$row['{column}']";

Open in new window


Author Comment

ID: 22715792
no thats to long i want something fast like the match command

Expert Comment

by:Sander Stad
ID: 22718284
How do you man it is too long. I only gave an example how you can test it. You don't have to use the whole code. You only have to use the the first 5 rows. The rest is just meant as an example.
By the way you'd have to use the rest in some way because you'd have to execute the query against the database.

Author Comment

ID: 22727307
i mean it takes alout of time i have a huge database
now its 6 million rows

Accepted Solution

wellso earned 250 total points
ID: 22728324
have you thought about using a FULLTEXT index?

Assisted Solution

by:Sander Stad
Sander Stad earned 250 total points
ID: 22728420

I think you misunderstood what I meant with the code to split up the searchstring. The reason why I split up the searchstring is that you want to be able to find a part of the string in your database.
You'll probably only want to search for the first part of a url and that is what you'll get with the code I posted. You can even create an if-statement to search the rest of the database with rest of the pieces of url that are in the searchstring if there is no result in the first part.
I didn't mean that you'd have to split up every url in the 6 million row database. Only the searchstring that somebody or something sends to the server to search for.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question