Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
Ajax Search (Vanilla JS)
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / Torrent Trader / v3 Mods Completed

Unknown User
2020-05-10 17:24:00
A lightweight script which I wrote today (Works with modern and older browsers IE 6+). You can create a new .JS, .PHP, and .CSS file to separate those, but I was lazy to do so, so here goes all together.

To include more data, you can change the line: [ICODE]$response .= '<div class="results"><a href="/torrents-details.php?id=' . $i['id'] . '">' . $i['name'] . '</a></div>';[/ICODE]
The hard limit is that search query must have at least 4 characters (to avoid db stressing)

To do a quick test, create a new test.php file

<?php
include 'backend/functions.php';
dbconn();

// This is the PHP side ajax check
if (isset($_GET['ajax']) && $_GET['ajax'] === '1')
{
   if ($_SERVER['REQUEST_METHOD'] === 'POST')
   {
       $searchstr = strtolower(trim($_POST["query"]));
       $search = "MATCH (torrents.name) AGAINST ('".mysqli_real_escape_string($GLOBALS["DBconnector"],$searchstr)."' IN BOOLEAN MODE)";
       if (!empty($_POST["query"]) && strlen($_POST["query"]) >= 4)
       {
           // You can JOIN tables here to get more information about torrents. (But will affect performance)
           $stmt = SQL_Query_exec("SELECT * FROM torrents WHERE $search LIMIT 10");
           $row = mysqli_fetch_assoc($stmt);
       }
   }

   echo '<div class="ls_box">
<div style="text-align: center;border-bottom: 1px solid #eee;padding-bottom: 5px;">Found results for <span style="color: #e6750c; ">' . $_POST['query'] . '</span></div>';
   if ($row)
   {
       $response = '';
       foreach ($stmt as $i)
       {
           $response .= '<div class="results"><a href="/torrents-details.php?id=' . $i['id'] . '">' . $i['name'] . '</a></div>';
       }
   }
   else
   {
       $response = '<div class="results">No results found</div>';
   }
   echo $response;
   echo '</div>';
   die;
}

stdhead('ajax search');
begin_frame('ajax search');
?>

Search torrents: <input type="text" onkeyup="ajaxSearch(this.value)" name="query" />
<div id="ajaxSearchStatus"></div>

<style>
   .ls_box {
       position: absolute;
       background: #fff;
       width: 20%;
       border-bottom: 0;
       border-radius: 10px;
       padding: 10px;
       box-shadow: 0 1px 4px rgba(0,0,0,.1);
       font-weight: bold;
   }
   .results {
       border-bottom: 1px solid #eee;
       padding: 5px;
       word-wrap: break-word;
   }
   .results a {
       color: #111;
       text-decoration: none;
   }
   .results a:hover {
       color: #333;
   }
   .results:hover {
       background: #e6750c3b;
       border-right: 2px solid #e6750c;
   }
</style>

<script type="text/javascript">
   function ajaxSearch(str)
   {
       var xhttp;
       if (str.length < 4) {
           document.getElementById("ajaxSearchStatus").innerHTML= '';
           return false;
       }
       // Modern browser support
       if (window.XMLHttpRequest)
       {
           xhttp = new XMLHttpRequest();
       }
       // Old browser support (IE 6+)
       else
       {
           xhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
       var url = '?ajax=1';
       var params = 'query=' + str;
       xhttp.open("POST", url, true);

       // Send the proper header information along with the request
       xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

       // What to do with the response
       xhttp.onreadystatechange = function()
       {
           if (this.readyState === 4 && this.status === 200)
           {
               document.getElementById("ajaxSearchStatus").innerHTML = this.responseText;
           }
       };
       // Send the post fields
       xhttp.send(params);
       // Until data returned, show custom text
       document.getElementById("ajaxSearchStatus").innerHTML = '<div class="ls_box">Loading data...</div>';
   }
</script>
<?php
end_frame();
stdfoot();


Preview:
2020-05-10 19:00:31
nice. Thanks for sharing
TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
2020-05-16 15:19:56
"shadows, post: 68547, member: 20311":

A lightweight script which I wrote today (Works with modern and older browsers IE 6+). You can create a new .JS, .PHP, and .CSS file to separate those, but I was lazy to do so, so here goes all together.

To include more data, you can change the line: [ICODE]$response .= '<div class="results"><a href="/torrents-details.php?id=' . $i['id'] . '">' . $i['name'] . '</a></div>';[/ICODE]
The hard limit is that search query must have at least 4 characters (to avoid db stressing)

To do a quick test, create a new test.php file

<?php
include 'backend/functions.php';
dbconn();

// This is the PHP side ajax check
if (isset($_GET['ajax']) && $_GET['ajax'] === '1')
{
   if ($_SERVER['REQUEST_METHOD'] === 'POST')
   {
       $searchstr = strtolower(trim($_POST["query"]));
       $search = "MATCH (torrents.name) AGAINST ('".mysqli_real_escape_string($GLOBALS["DBconnector"],$searchstr)."' IN BOOLEAN MODE)";
       if (!empty($_POST["query"]) && strlen($_POST["query"]) >= 4)
       {
           // You can JOIN tables here to get more information about torrents. (But will affect performance)
           $stmt = SQL_Query_exec("SELECT * FROM torrents WHERE $search LIMIT 10");
           $row = mysqli_fetch_assoc($stmt);
       }
   }

   echo '<div class="ls_box">
<div style="text-align: center;border-bottom: 1px solid #eee;padding-bottom: 5px;">Found results for <span style="color: #e6750c; ">' . $_POST['query'] . '</span></div>';
   if ($row)
   {
       $response = '';
       foreach ($stmt as $i)
       {
           $response .= '<div class="results"><a href="/torrents-details.php?id=' . $i['id'] . '">' . $i['name'] . '</a></div>';
       }
   }
   else
   {
       $response = '<div class="results">No results found</div>';
   }
   echo $response;
   echo '</div>';
   die;
}

stdhead('ajax search');
begin_frame('ajax search');
?>

Search torrents: <input type="text" onkeyup="ajaxSearch(this.value)" name="query" />
<div id="ajaxSearchStatus"></div>

<style>
   .ls_box {
       position: absolute;
       background: #fff;
       width: 20%;
       border-bottom: 0;
       border-radius: 10px;
       padding: 10px;
       box-shadow: 0 1px 4px rgba(0,0,0,.1);
       font-weight: bold;
   }
   .results {
       border-bottom: 1px solid #eee;
       padding: 5px;
       word-wrap: break-word;
   }
   .results a {
       color: #111;
       text-decoration: none;
   }
   .results a:hover {
       color: #333;
   }
   .results:hover {
       background: #e6750c3b;
       border-right: 2px solid #e6750c;
   }
</style>

<script type="text/javascript">
   function ajaxSearch(str)
   {
       var xhttp;
       if (str.length < 4) {
           document.getElementById("ajaxSearchStatus").innerHTML= '';
           return false;
       }
       // Modern browser support
       if (window.XMLHttpRequest)
       {
           xhttp = new XMLHttpRequest();
       }
       // Old browser support (IE 6+)
       else
       {
           xhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
       var url = '?ajax=1';
       var params = 'query=' + str;
       xhttp.open("POST", url, true);

       // Send the proper header information along with the request
       xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

       // What to do with the response
       xhttp.onreadystatechange = function()
       {
           if (this.readyState === 4 && this.status === 200)
           {
               document.getElementById("ajaxSearchStatus").innerHTML = this.responseText;
           }
       };
       // Send the post fields
       xhttp.send(params);
       // Until data returned, show custom text
       document.getElementById("ajaxSearchStatus").innerHTML = '<div class="ls_box">Loading data...</div>';
   }
</script>
<?php
end_frame();
stdfoot();


Preview:


thanks you!

he finds nothing at home, thank you for your help.

<?php
require_once('backend/functions.php');
dbconn();

// This is the PHP side ajax check
if (isset($_GET['ajax']) && $_GET['ajax'] === '1')
{
   if ($_SERVER['REQUEST_METHOD'] === 'POST')
   {
       $searchstr = strtolower(trim($_POST["query"]));
       $search = "MATCH (torrents.name) AGAINST ('".mysqli_real_escape_string($GLOBALS["DBconnector"],$searchstr)."' IN BOOLEAN MODE)";
       if (!empty($_POST["query"]) && strlen($_POST["query"]) >= 4) //4 characters minum (to avoid db stressing)
       {
           // You can JOIN tables here to get more information about torrents. (But will affect performance)
           $stmt = SQL_Query_exec("SELECT * FROM torrents WHERE $search LIMIT 10");
           $row = mysqli_fetch_assoc($stmt);
       }
   }

   echo '<div class="ls_box">
<div style="text-align: center;border-bottom: 1px solid #B2B2B2;padding-bottom: 5px;color:#222;">Résultats trouvés pour <span style="color: blue; ">' . $_POST['query'] . '</span></div>';
   if ($row)
   {
       $response = '';
       foreach ($stmt as $x)
       {
           $response .= '<div class="results"><a href="/torrents-details.php?id=' . $x['id'] . '">' . $x['name'] . '</a></div>';
       }
   }
   else
   {
       $response = '<div class="results" style="cOlor:black;"><i>...Aucun Résultat Trouvé!</i></div>';
   }
   echo $response;
   echo '</div>';
   die;
}

stdhead('ajax search');
begin_frame('ajax search');
?>

Rechercher des torrents: <input type="text" onkeyup="ajaxSearch(this.value)" name="query" />
<div id="ajaxSearchStatus"></div>

<style>
   .ls_box {
       position: absolute;
       background: #fff;
       width: 20%;
       border-bottom: 0;
       border-radius: 10px;
       padding: 10px;
       box-shadow: 0 1px 4px rgba(0,0,0,.1);
       font-weight: bold;
   }
   .results {
       border-bottom: 1px solid #eee;
       padding: 5px;
       word-wrap: break-word;
   }
   .results a {
       color: #111;
       text-decoration: none;
   }
   .results a:hover {
       color: #333;
   }
   .results:hover {
       background: #e6750c3b;
       border-right: 2px solid #e6750c;
   }
</style>

<script type="text/javascript">
   function ajaxSearch(str)
   {
       var xhttp;
       if (str.length < 4) {
           document.getElementById("ajaxSearchStatus").innerHTML= '';
           return false;
       }
       // Modern browser support
       if (window.XMLHttpRequest)
       {
           xhttp = new XMLHttpRequest();
       }
       // Old browser support (IE 6+)
       else
       {
           xhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
       var url = '?ajax=1';
       var params = 'query=' + str;
       xhttp.open("POST", url, true);

       // Send the proper header information along with the request
       xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

       // What to do with the response
       xhttp.onreadystatechange = function()
       {
           if (this.readyState === 4 && this.status === 200)
           {
               document.getElementById("ajaxSearchStatus").innerHTML = this.responseText;
           }
       };
       // Send the post fields
       xhttp.send(params);
       // Until data returned, show custom text
       document.getElementById("ajaxSearchStatus").innerHTML = '<div class="ls_box">Chargement des données...</div>';
   }
</script>
<?php
end_frame();
stdfoot();



Unknown User
2020-05-23 14:23:37
Open inspector tool, go to console and see if there is some error log.
2020-05-24 15:39:42
"shadows, post: 68642, member: 20311":

Open inspector tool, go to console and see if there is some error log.

hello shadows
no mistake
Unknown User
2020-05-26 12:17:33
Your torrents name table must have full-text index and you have to use mysqli version of torrent trader.
2020-05-28 03:32:20
[URL unfurl="true"]https://stackoverflow.com/questions/8454961/php-fulltext-search-with-pdo[/url]
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 9
  • Members: 0
  • Guests online: 9
  • Comments: 3
  • Messages: 1,728