Jump to content

Search Results Links


justlukeyou

Recommended Posts

Hi,

 

I have a search script which currently searches the details of users. However I am trying to add the option to search other tables. The problem is with the current code echoes the content into a set link.

 

<a href="/profilepages/profile<?php echo ''.$result['usertypelink'].''; ?>.php?ID=<?php echo $row['id']; ?>

 

The problem is that if I am searching other tables I need to use different links.

 

Their are two options I can think of (probably both wrong)

 

1. Use if statesments which sounds very complicated.

2. Echo the link from the database!

 

<a href="<?php echo ''.$result['searchlink'].'', ''.$result['usertypelink'].''; ?>.php?<?php echo $row['query']; ?>=<?php echo $row['id']; ?>

 

Im unsure about both. Does any suggestions on what I can use?

Edited by justlukeyou
Link to comment
Share on other sites

How does the link actually fit in with the search? Usually a search is initiated in a form, where the search term is used in a JOIN of some sort.

 

If you can describe your current search process (looks like it has something to do with gamer profiles), that would help.

Link to comment
Share on other sites

Hi,

 

The search code is seperate to the forum. Im trying to find the simplest way to do it. Is there a standard way of producing search results from different tables?

 

 

 

<form action="/test/searchoutput.php" method="post">
<input type="text" name="keywords" size="20" placeholder='perform a search...' class="internalsearch" />
</div>
<div class="internalsearchimagecell">
<input type="image"  value="Submit" src="/images/internalsearch.png" alt="Search" name="image" />
</div>
</form>

 

 

<div class="searchresults">
<div class="imagesearchresults">
<a href="http://website.com"  rel="nofollow" >
<a href="/profilepages/profile<?php echo ''.$result['usertypelink'].''; ?>.php?ID=<?php echo $row['id']; ?>"  rel="nofollow" >
<img src="/test//images/<?php echo ''.$result['logo'].''; ?>" /></a>
</div>
<div class="datasearchresults">
<div class="companysearchresults">
<a href="/profilepages/profile<?php echo ''.$result['usertypelink'].''; ?>.php?ID=<?php echo $row['id']; ?>"  rel="nofollow" >
<?php echo ''.$result['company'].''; ?>
</a>
</div>
<div class="companysearchresults">
<?php echo ''.$result['category'].''; ?> (<?php echo ''.$result['usertype'].''; ?>)
</div>
<div class="companysearchresults">
<?php echo ''.$result['firstname'].''; ?> <?php echo ''.$result['surname'].''; ?>
</div>
<div class="companysearchresults"> 
<?php echo ''.$result['town'].''; ?> | <?php echo ''.$result['country'].''; ?> | <?php echo ''.$result['postcode'].''; ?> 
</div>
</div>



<?php
}
   ?>
</div>



<?php
} else {
foreach($errors as $error) {
echo $error, '</br>';
}
}
   ?>


<?php
function search_results ($keywords) {
$returned_results = array();
$where = "";

$keywords = preg_split('/[\s]+/', $keywords);
$total_keywords = count($keywords);

foreach($keywords as $key=>$keyword) {
$where .= "`firstname` LIKE '%$keyword%' OR `surname` LIKE '%$keyword%' OR `category` LIKE '%$keyword%' OR `company` LIKE '%$keyword%' OR `town` LIKE '%$keyword%' OR `country` LIKE '%$keyword%'";
if ($key != ($total_keywords - 1)) {
$where .= " AND ";

}
}

$results = "SELECT `usertype`, `usertypelink`, `id`, `firstname`, `surname`, `category`, `company`, `logo`, `town`, `country`, `postcode` FROM `users` WHERE $where LIMIT 20";

$results_num = ($results = mysql_query($results)) ? mysql_num_rows($results) : 0;

if ($results_num === 0) {
return false;
}else{

while ($results_row = mysql_fetch_assoc($results)) {

$returned_results[] = array(
                   'usertype' => $results_row['usertype'],
				'usertypelink' => $results_row['usertypelink'],
                   'id' => $results_row['id'],
                   'firstname' => $results_row['firstname'],
                   'surname' => $results_row['surname'],	
                   'category' => $results_row['category'],
                   'company' => $results_row['company'],	
                   'logo' => $results_row['logo'],	
                   'town' => $results_row['town'],	
                   'country' => $results_row['country'],	
                   'postcode' => $results_row['postcode'],						
);

}

return $returned_results;

}
}
?>

</div>		

Link to comment
Share on other sites

There's no standardized way to do it because it depends on your table structure and what you want to return.

 

So, if you want to roll your own, you'll need to employ some combination of INNER JOIN, DISTINCT, and/or UNION. In that case, show us your table structure and what info you'd like to return.

 

The other option is to use 3rd party fulltext search, like Lucene or Sphinx (MySQL itself comes with fulltext search, but I've heard it's slow).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.