Advertisement
Superloup10

Untitled

Aug 16th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. function searchTutorialByName($tutoname)
  2. {
  3.     global $db;
  4.     $query = $db->write_query("SELECT subject, tid, threadprefix.prefix FROM mybb_threads AS thread, mybb_threadprefixes AS threadprefix WHERE pid=thread.prefix AND subject LIKE '%". $tutoname . "%'");
  5.  
  6.     $tid = [];
  7.     $prefix = [];
  8.     $subject = [];
  9.     while($result = $db->fetch_array($query)) {
  10.         $subject[] = $result['subject'];
  11.         $tid[] = $result['tid'];
  12.         $prefix[] = $result['prefix'];
  13.     }
  14.  
  15.     $data = array(
  16.         "prefix" => $prefix,
  17.         "subject" => $subject,
  18.         "tid" => $tid
  19.     );
  20.  
  21.     return json_encode($data, JSON_UNESCAPED_UNICODE);
  22.  
  23.     /*$data = array(
  24.         "tutorial" => []
  25.     );*/
  26.  
  27.     /*for ($i = 0; $i < count($prefix); $i++) {
  28.         if (array_key_exists($prefix[$i], $data["tutorial"])) {
  29.             $new_tid = $data["tutorial"][$prefix[$i]];
  30.             $new_tid[$subject[$i]] = $tid[$i];
  31.  
  32.             $data["tutorial"] = array_replace($data["tutorial"],
  33.                 array_fill_keys(
  34.                     array_keys($data["tutorial"], $data["tutorial"][$prefix[$i]]),
  35.                     $new_tid
  36.                 )
  37.             );
  38.         } else {
  39.             $data["tutorial"][$prefix[$i]] = array($subject[$i] => $tid[$i]);
  40.         }
  41.     }
  42.  
  43.     return json_encode($data,  JSON_UNESCAPED_UNICODE);*/
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement