Test Ar-PHP Functionality Online

header line!
Test PHP Function










Ar-PHP Manual

method getOrderBy [line 416]

string getOrderBy( string $arg)

Get more relevant order by section related to the user search keywords



Tags:

return:  sub SQL ORDER BY section
author:  Saleh AlMatrafe <saleh@saleh.cc>
access:  public


Parameters:

string   $arg   String that user search for in the database table

Example
  1.      include('./I18N/Arabic.php');
  2.      $obj = new I18N_Arabic('Query');
  3.  
  4.      $dbuser = 'root';
  5.      $dbpwd = '';
  6.      $dbname = 'test';
  7.  
  8.      try {
  9.          $dbh = new PDO('mysql:host=localhost;dbname='.$dbname, $dbuser, $dbpwd);
  10.  
  11.          // Set the error reporting attribute
  12.          $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  13.  
  14.          $dbh->exec("SET NAMES 'utf8'");
  15.  
  16.          if ($_GET['keyword'] != '') {
  17.              $keyword = @$_GET['keyword'];
  18.              $keyword = str_replace('\"', '"', $keyword);
  19.  
  20.              $obj->setStrFields('headline');
  21.              $obj->setMode($_GET['mode']);
  22.  
  23.              $strCondition = $Arabic->getWhereCondition($keyword);
  24.          } else {
  25.              $strCondition = '1';
  26.          }
  27.  
  28.          $StrSQL = "SELECT `headline` FROM `aljazeera` WHERE $strCondition";
  29.  
  30.          $i = 0;
  31.          foreach ($dbh->query($StrSQL) as $row) {
  32.              $headline = $row['headline'];
  33.              $i++;
  34.              if ($i % 2 == 0) {
  35.                  $bg = "#f0f0f0";
  36.              } else {
  37.                  $bg = "#ffffff";
  38.              }
  39.              echo "<tr bgcolor=\"$bg\"><td>$headline</td></tr>";
  40.          }
  41.  
  42.          // Close the databse connection
  43.          $dbh = null;
  44.  
  45.      } catch (PDOException $e) {
  46.          echo $e->getMessage();
  47.      }
Popular
Recent
Links
Ads!
footer line!

No Software Patents! General Public License

Home | Twitter | Blog | Contact

Copyright © 2006 - 2016 Khaled Al-Sham'aa