So would I do something like
SELECT FROM table1 WHERE column1='$foo' IN table1 WHERE column1='$foo2'
Is that right? Just guess work :p
For starters that mysql query is wrong and I shall share a way help answer this question. First to retrieve all site: within a string use the following:
$string='test site:example.com site:test.com test2';
if (preg_match('/site:/i',$string))
{
preg_match_all('/site:[^ ]+/i',$string,$site);
for ($ii=0;isset($site[0][$ii]);$ii++)
{
$site[0][$ii]=strtolower(substr($site[0][$ii],5,strlen($site[0][$ii])));
}
$sites=$site[0]; unset($site);
//now to display it
foreach ($sites AS $siteval)
{
echo $siteval."";
}
}
That will turn it into the $sites array. The reason why an array is just in case there is more than one site specified. Then to do the mysql query it would be something like the following:
mysql_query("SELECT * FROM `table` WHERE `domain`='".mysql_real_escape_string($sites[0])."'");
cwarn23
Occupation: Genius
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259
Thats amazing, thank you so much. What I will have to do is to tell my users to set site:example.com first then put the query. To make it easier.
So, to get the query. Ive done this...
$search = explode(' ', $string);
echo $search[1];
It works but is pretty rudimentary, would you recomend something better?
Yes, using the explode function would be the best way to get all of the keywords but in your example, you have got the site:example.com as a keyword below is how I would do it.
$string='test site:example.com site:test.com test2';
if (preg_match('/site:/i',$string))
{
preg_match_all('/site:[^ ]+/i',$string,$site);
for ($ii=0;isset($site[0][$ii]);$ii++)
{
$site[0][$ii]=strtolower(substr($site[0][$ii],5,strlen($site[0][$ii])));
}
$sites=$site[0]; unset($site);
}
$search=explode(' ',preg_replace('/[\h]+/',' ',preg_replace('/site:[^\h]+/i','',$string)));
//now to display
echo "<b>Sites</b>";
foreach ($sites AS $siteval)
{
echo $siteval."";
}
echo "<b>Keywords</b>";
foreach ($search AS $val)
{
echo "".$val;
}
cwarn23
Occupation: Genius
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259
Hmm...doesnt seem to be working. Is this query valid?
SELECT * FROM list WHERE title LIKE '%$search%' AND where url LIKE '%$sites%'
The mysql query should look more like the following:
SELECT * FROM list WHERE title LIKE '%$search%' AND url LIKE '%$sites%'
or for my preference
mysql_query("SELECT * FROM `list` WHERE `title` LIKE '%".$search."%' AND `url` LIKE '%".$sites."%'");
Also note that$search and $sites must not be an array when used in the query. If you do use an array in a mysql query and you don't specify the exact value (example: $search[0]) Then it will just scan the database for the word 'Array'. So if $search and $sites are arrays then you may need to put the query inside a loop and for testing purposes you could use the following:
mysql_query("SELECT * FROM `list` WHERE `title` LIKE '%".$search[0]."%' AND `url` LIKE '%".$sites[0]."%'");
cwarn23
Occupation: Genius
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259