php - Limiting post sql results -
im building search engine scratch.
it scans many different tables in multiple databases. it searches through specified columns. the search wordsexplode()
'ed case of multiple words search it iterates foreach
through tables. i'm having problem structuring code base of operations limit
. want show distinct
.
for illustration if search joe schmoe
code search first = joe
, last = schmoe
, , display result each search. want display 1 result 2 searches.
<?php echo "<h1>search results</h1>"; echo "<table style='width: 100%;'>"; $a = $_get["q"]; $b = explode(" ", $a); include 'db_connect3.php'; mysql_select_db("db440035579", $con); foreach($b $c){ $sql="select * users first '%$c%' || lastly '%$c%'"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { echo "<a href='applications.php?act=search&uid=$row[7]'>$row[5], $row[4]</a>"; } } mysql_close($con); ?>
first of http://bobby-tables.com/
secondly, plugging in pdo
takes few lines of code.
thirdly, total text search much better.
and finally:
use array microcaching. assume $row[0]
user.id
. way 1 item per id
$cache = array(); foreach($b $c){ $sql="select * users first '%$c%' || lastly '%$c%'"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ $cache[$row[0]] = $row; } } foreach($cache $row){ echo "<a href='applications.php?act=search&uid=$row[7]'>$row[5], $row[4]</a>"; }
php mysql search-engine
No comments:
Post a Comment