Posted in Site Bugs
8968
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
130
This Month
461
This Year
1468

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

"Olivia, my eldest daughter, caught measles when she was seven years old. As the illness took its usual course I can remember reading to her often in bed and not feeling particularly alarmed about it. Then one morning, when she was well on the road to recovery, I was sitting on her bed showing her how to fashion little animals out of coloured pipe-cleaners, and when it came to her turn to make one herself, I noticed that her fingers and her mind were not working together and she couldn’t do anything. 'Are you feeling all right?' I asked her. 'I feel all sleepy,' she said. In an hour, she was unconscious. In twelve hours she was dead. The measles had turned into a terrible thing called measles encephalitis and there was nothing the doctors could do to save her. That was...in 1962, but even now, if a child with measles happens to develop the same deadly reaction from measles as Olivia did, there would still be nothing the doctors could do to help her. On the other hand, there is today something that parents can do to make sure that this sort of tragedy does not happen to a child of theirs. They can insist that their child is immunised against measles. ...I dedicated two of my books to Olivia, the first was ‘James and the Giant Peach’. That was when she was still alive. The second was ‘The BFG’, dedicated to her memory after she had died from measles. You will see her name at the beginning of each of these books. And I know how happy she would be if only she could know that her death had helped to save a good deal of illness and death among other children."

I just checked google books for BFG, and the dedication is there. 

https://www.google.com.au/books/edition/_/quybcXrFhCIC?hl=en&gbpv=1 


Roald Dahl, 1986
Random CSS Property

order

The order CSS property sets the order to lay out an item in a flex or grid container. Items in a container are sorted by ascending order value and then by their source code order.
order css reference