Posted in Site Bugs
567
6:39 am, May 20, 2022
 

Search Duplicating Bugs

<p>Still having issues with the word above duplicating, not sure why.&nbsp;</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="https://i.imgur.com/zU8zufI.png" /></p>
<h3>Search Page</h3>
<h4>PHP - Get Search Value</h4>
<pre><code class="php hljs">$searchvalueencoded = htmlentities($searchvalue);</code></pre>
<p>Check for Search value, and then list all items matching that value.</p>
<pre><code class="php hljs">if($search
value &gt; "") {
$pagecontent .= $class-&gt;listall(
$start = $startval,
$max = $page
step,
"search",
$templatefilename,
$searchterm = $searchvalue
);
}</code></pre>
<p>List type is search</p>
<h4>PHP</h4>
<pre><code class="php hljs">if($listtype == "search") {

$searchtermurlenc = rawurlencode($searchterm);
$searchtermurlenc = "searchtext:::" . $searchtermurlenc;

$searchsql = "";
foreach($this-&gt;loadarray as $loadvar) {
$searchsql .= "$loadvar like '%$searchterm%' or ";
}
$search
sql = rtrim($searchsql,"or ");

/ -- old search sql
$sql = "select
from $db
tablename where
title like '%$search
term%' or
additional like '%$searchterm%' or
category like '%$search
term%' or
uid like '%$searchterm%'
order by insdate desc limit $start,$max";
/

$sql = "select from $dbtablename where
$search
sql
order by insdate desc limit $start,$max
";

}</code></pre>
<p>Add search function, i think there might be an issue here</p>
<h4>PHP</h4>
<pre><code class="php hljs">/ add search result /
if( $out &gt; "" ) {
// record search term if enabled
if($listtype == "search") {
global $record
searches;
$recordsearchval = true;

// if the search value is from comments and its 5 then its a uid so dont record it.
if($dbtablename == "comments") {
if(strlen($searchterm) &lt;= 5) {
$record
searchval = false; // skip the uid search recording
}
}

if($recordsearches &amp;&amp; $recordsearchval) {
$searches = new searches;
$searches-&gt;start();
if($searches-&gt;loadfromtitle($this-&gt;dbtablename . " " . $searchterm)) {
// update existing
$searches-&gt;search
number = $searches-&gt;searchnumber + 1;
$searches-&gt;update();
} else {
// add search
$searches-&gt;title = $this-&gt;db
tablename . " " . $searchterm;
$searches-&gt;searchterm = $searchterm;
$searches-&gt;searchclass = $this-&gt;dbtablename;
$searches-&gt;search
number = 1;
$searches-&gt;add();
}
}
}

}
/ add search result /</code></pre>
<p>I think the load from title may be an issue here, may need to add a md5 of the class and title name to fix this.&nbsp;</p>
<p>Add md5 field to the searches class extend</p>
<h4>PHP</h4>
<pre><code class="php hljs"> public $loadarray = [
"id",
"uid",
"insdate",
"title",
"additional",
"category",
"search
term",
"searchclass",
"search
number",
"md5",
];</code></pre>
<p>Also append the searches db table with a new md5 field</p>
<p>Another bug editing the db.</p>
<p>Prob an old or very old version of php lite admin,&nbsp;</p>
<div>
<div>Version: 1.9.8-dev</div>
</div>
<p>Added md5 to search class, and sqlite, need to find loadfrommd5 function and add it.&nbsp;</p>
<p>this is not quite what i wanted, i might modify it a bit.</p>
<h4>PHP</h4>
<pre><code class="php hljs">// check if a product already exists by its md5
public function md5exists($md5) {
$db
tablename = $this-&gt;db-&gt;escapeString($this-&gt;dbtablename);
$md5 = $this-&gt;db-&gt;escapeString($md5);
$sql = "select id from $db
tablename where md5 = '$md5' limit 1";
$result = $this-&gt;db-&gt;query($sql);
if(!$result) { return false; }
while($row = $result-&gt;fetchArray()) {
$this-&gt;id = $row['id'];
return true;
}
return false;
}</code></pre>
<p>Ok i have fixed this record searches with a md5 added to the row rather than it loading from the title.</p>
<p>Seems to be working, as there are no longer multiple above searches appearing, and it is now updating latest searches properly.&nbsp;</p>
<h4>PHP</h4>
<pre><code class="php hljs"> // if there is something in out and it is a search result then record it.
/ add search result /
if( $out &gt; "" ) {
// record search term if enabled
if($list
type == "search") {
global $recordsearches;
$record
searchval = true;

// if the search value is from comments and its 5 then its a uid so dont record it.
if($db
tablename == "comments") {
if(strlen($search
term) &lt;= 5) {
$recordsearchval = false; // skip the uid search recording
}
}

if($recordsearches &amp;&amp; $recordsearchval) {
$searches = new searches;
$searches-&gt;start();
// md5
exists(md5)
$searchtitletable = $this-&gt;dbtablename . " " . $searchterm;
$md5
searchtitle = md5($searchtitletable);
// if($searches-&gt;load
fromtitle($searchtitletable)) {
if($searches-&gt;md5
exists($md5searchtitle)) {
// update existing
if($searches-&gt;loadfromid($searches-&gt;id)) {
$searches-&gt;searchnumber = $searches-&gt;searchnumber + 1;
$searches-&gt;update();
}
} else {
// add search
$searches-&gt;title = $this-&gt;dbtablename . " " . $searchterm;
$searches-&gt;search
term = $searchterm;
$searches-&gt;search
class = $this-&gt;dbtablename;
$searches-&gt;searchnumber = 1;
$searches-&gt;md5 = $md5
search_title;
$searches-&gt;add();
}
}
}

}
/ add search result /</code></pre>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="https://i.imgur.com/oMCsNeL.png" /></p>
<h3>Git Commit Differences</h3>
<p><img src="https://i.imgur.com/4Z1C8Iv.png" /></p>

View Statistics
This Week
342
This Month
1271
This Year
777

No Items Found.

Add Comment
Type in a Nick Name here
 
Related Search Terms
Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

You could also follow me on twitter. I have a couple of youtube channels if you want to see some video related content. RuneScape 3, Minecraft and also a coding channel here Web Dev.

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote

is backupper a word?
anytrans
Latest News
## 🚀 AI Giants Hit Bullseye: Anthropic & OpenAI Achieve Product-Market Fit Anthropic and OpenAI have reached a significant milestone, finding product-market fit with their AI technologies, which means their products effectively meet the needs of their customers, driving growth and adoption. This achievement showcases the practical value of their innovations, enabling businesses and individuals to leverage AI for enhanced productivity and efficiency. With this alignment of product and market needs, these companies are poised to transform industries and shape the future of technology.