justlukeyou Posted January 4, 2013 Share Posted January 4, 2013 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? Link to comment https://forums.phpfreaks.com/topic/272710-search-results-links/ Share on other sites More sharing options...
KevinM1 Posted January 5, 2013 Share Posted January 5, 2013 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 https://forums.phpfreaks.com/topic/272710-search-results-links/#findComment-1403325 Share on other sites More sharing options...
justlukeyou Posted January 5, 2013 Author Share Posted January 5, 2013 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 https://forums.phpfreaks.com/topic/272710-search-results-links/#findComment-1403381 Share on other sites More sharing options...
KevinM1 Posted January 5, 2013 Share Posted January 5, 2013 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 https://forums.phpfreaks.com/topic/272710-search-results-links/#findComment-1403436 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.