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

Search Duplicating Bugs

Still having issues with the word above duplicating, not sure why. 

Search Page

PHP - Get Search Value

$search_value_encoded = htmlentities($search_value);

Check for Search value, and then list all items matching that value.

if($search_value > "") {
    $page_content .= $class->list_all(
        $start = $start_val,
        $max = $page_step,
        "search",
        $template_file_name,
        $search_term = $search_value
    );
}

List type is search

PHP

if($list_type == "search") {

    $search_term_urlenc = rawurlencode($search_term);
    $search_term_urlenc = "search_text:::" . $search_term_urlenc;

    $search_sql = "";
    foreach($this->load_array as $load_var) {
        $search_sql .= "$load_var like '%$search_term%' or ";
    }
    $search_sql = rtrim($search_sql,"or ");

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

    $sql = "select * from $db_table_name where
    $search_sql
    order by insdate desc limit $start,$max
    ";

}

Add search function, i think there might be an issue here

PHP

/* add search result  */
if( $out > "" ) {
    // record search term if enabled
    if($list_type == "search") {
      global $record_searches;
      $record_search_val = true;

      // if the search value is from comments and its 5 then its a uid so dont record it.
      if($db_table_name == "comments") {
        if(strlen($search_term) <= 5) {
          $record_search_val = false; // skip the uid search recording
        }
      }

      if($record_searches && $record_search_val) {
        $searches = new searches;
        $searches->start();
        if($searches->load_from_title($this->db_table_name . " " . $search_term)) {
          // update existing
          $searches->search_number = $searches->search_number + 1;
          $searches->update();
        } else {
          // add search
          $searches->title = $this->db_table_name . " " . $search_term;
          $searches->search_term = $search_term;
          $searches->search_class = $this->db_table_name;
          $searches->search_number = 1;
          $searches->add();
        }
      }
    }

}
/* add search result  */

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. 

Add md5 field to the searches class extend

PHP

  public $load_array = [
    "id",
    "uid",
    "insdate",
    "title",
    "additional",
    "category",
    "search_term",
    "search_class",
    "search_number",
    "md5",
  ];

Also append the searches db table with a new md5 field

Another bug editing the db.

Prob an old or very old version of php lite admin, 

Version: 1.9.8-dev

Added md5 to search class, and sqlite, need to find load_from_md5 function and add it. 

this is not quite what i wanted, i might modify it a bit.

PHP

// check if a product already exists by its md5
public function md5_exists($md5) {
    $db_table_name = $this->db->escapeString($this->db_table_name);
    $md5 = $this->db->escapeString($md5);
    $sql = "select id from $db_table_name where md5 = '$md5' limit 1";
    $result = $this->db->query($sql);
    if(!$result) { return false; }
    while($row = $result->fetchArray()) {
        $this->id = $row['id'];
        return true;
    }
    return false;
}

Ok i have fixed this record searches with a md5 added to the row rather than it loading from the title.

Seems to be working, as there are no longer multiple above searches appearing, and it is now updating latest searches properly. 

PHP

        // if there is something in out and it is a search result then record it.
        /* add search result  */
        if( $out > "" ) {
            // record search term if enabled
            if($list_type == "search") {
              global $record_searches;
              $record_search_val = true;

              // if the search value is from comments and its 5 then its a uid so dont record it.
              if($db_table_name == "comments") {
                if(strlen($search_term) <= 5) {
                  $record_search_val = false; // skip the uid search recording
                }
              }

              if($record_searches && $record_search_val) {
                $searches = new searches;
                $searches->start();
                // md5_exists(md5)
                $search_title_table = $this->db_table_name . " " . $search_term;
                $md5_search_title = md5($search_title_table);
                // if($searches->load_from_title($search_title_table)) {
                if($searches->md5_exists($md5_search_title)) {
                  // update existing
                  if($searches->load_from_id($searches->id)) {
                    $searches->search_number = $searches->search_number + 1;
                    $searches->update();
                  }
                } else {
                  // add search
                  $searches->title = $this->db_table_name . " " . $search_term;
                  $searches->search_term = $search_term;
                  $searches->search_class = $this->db_table_name;
                  $searches->search_number = 1;
                  $searches->md5 = $md5_search_title;
                  $searches->add();
                }
              }
            }

        }
        /* add search result  */

Git Commit Differences

View Statistics
This Week
372
This Month
1252
This Year
4600

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...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

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

james clear
Random CSS Property

table-layout

The table-layout CSS property sets the algorithm used to lay out <table> cells, rows, and columns.
table-layout css reference