Solved

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

Posted on 2008-10-13
9
276 Views
Last Modified: 2008-10-25
lets say i have this links in the database
------------------------------------------------------------
www.dsdxa.com/23432324/dswd2.rar
www.dsdxa.com/2423432/dswd4.rar
www.dsdxa.com/34242/dswd3.rar
www.dsdxa.com/34242/dsadsad3.rar
www.dsadwa.com/34242/dssqasd3.rar

--------------------------------------------------------------
and i want to search for all the links that look like
www.dsdxa.com/34242/dswd1.rar
want the command to output
www.dsdxa.com/23432324/dswd2.rar
www.dsdxa.com/2423432/dswd4.rar
www.dsdxa.com/34242/dswd3.rar

and not
www.dsdxa.com/34242/dsadsad3.rar
www.dsadwa.com/34242/dssqasd3.rar
------------------------------------------------------------------
i know this command the like command but its not working as u want
----------------------------------------------------------------------
thanks
0
Comment
Question by:mgtm3
  • 4
  • 4
9 Comments
 
LVL 9

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?
0
 

Author Comment

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

Author Comment

by:mgtm3
ID: 22713871
soo anyone?
0
 
LVL 9

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.


<?php

$link = "www.dsdxa.com";

$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

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:mgtm3
ID: 22715792
no thats to long i want something fast like the match command
0
 
LVL 9

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.
 
0
 

Author Comment

by:mgtm3
ID: 22727307
i mean it takes alout of time i have a huge database
now its 6 million rows
0
 
LVL 2

Accepted Solution

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

http://www.onlamp.com/pub/a/onlamp/2003/06/26/fulltext.html
0
 
LVL 9

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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
calculated column 12 74
Calculating number of days between two dates 7 30
php string masking 4 27
Is it okay to create multiple session variables with user data upon login 8 20
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
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.

937 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

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now