title: Get individual ID of ROW, and make the result linkable
body: <p>I need to get the <em>'id'</em> column from my table <em>'reports'</em> to get the unique value and make it linkable.</p>
  
  <p>The link of the element has this format: <em><a href="http://www.mysite.com/id" rel="nofollow">http://www.mysite.com/id</a>,</em>  (coma included)</p>
  
  <p>Can you help me how to get the info from <em>id</em> column and make it clikable in the results?</p>
  
  <pre><code>&lt;?php
  
  
  
      $MySQLPassword = "*****";   
      $HostName = "***";  
      $UserName = "***";
      $Database = "****";
  
      mysql_connect($HostName,$UserName,$MySQLPassword)
      or die("ERROR: Could not connect to database!");
      mysql_select_db($Database) or die("cannot select db");
  
  
      $default_sort = 'ID';
      $allowed_order = array ('name','description');
  
      if (!isset ($_GET['order']) || 
          !in_array ($_GET['order'], $allowed_order)) {
          $order = $default_sort;
      } else {
          $order = $_GET['order'];
      }
  
  
      if (isset($_GET['keyword'])) {
  
              if(!$_GET['keyword']) {
                die('&lt;p&gt;Please enter a search term.&lt;/p&gt;');
          }     
  
  
  
  
  
  /////////////////////////HERE IS THE BEGINING OF CODE WHERE I THINK SHOULD BE THE PROBLEM ////////////////////////////
  
      $tables = 'reports';
      $return_fields = 'name organizer_id no_pages publication_date price';
      $check_fields = 'name description';
  
  
      $query_text = $_GET['keyword'];
  
      $clean_query_text =cleanQuery($query_text);
  
      $newquery=bq_simple ($return_fields, $tables, $check_fields, $clean_query_text);
      $newquery = $newquery . " ORDER BY $order;";
  
      $result = mysql_query($newquery) or die(mysql_error());
  
  
      $numrows = mysql_num_rows($result);
      if ($numrows == 0) {
          echo "&lt;H4&gt;No data to display!&lt;/H4&gt;";
          exit;
      }
      echo    "&lt;p&gt;Your search '$query_text' returned ".$numrows. " results.&lt;/p&gt;\n";
      echo    "&lt;p&gt;Click on the headings to sort.&lt;/p&gt;\n";
  
      $row = mysql_fetch_assoc ($result);
      echo "&lt;TABLE border=1&gt;\n";
      echo "&lt;TR&gt;\n";
      foreach ($row as $heading=&gt;$column) {
  
  
          echo "&lt;TD&gt;&lt;b&gt;";
          if (in_array ($heading, $allowed_order)) {
              echo "&lt;a href=\"{$_SERVER['PHP_SELF']}?order=$heading&amp;keyword=$query_text\"&gt;$heading&lt;/a&gt;";
          } else {
              echo $heading;
          }                
          echo "&lt;/b&gt;&lt;/TD&gt;\n";
      }
      echo "&lt;/TR&gt;\n";
  
      $results = mysql_query("SELECT id, name FROM reports WHERE id = $id") or die(mysql_error());
      while ($row = mysql_fetch_assoc ($result)) {
          echo "&lt;TR&gt;\n";
  
          echo '&lt;a href="mysite.com/' . $row['id'] . ',"&gt;' . $row['name'] . '&lt;/a&gt;';
          echo "&lt;/TR&gt;\n";
      }
      echo "&lt;/TABLE&gt;\n";
      }
  
  ////////////////////////FINISH OF THE CODE WITH PROBLEM ////////////////////////////
  
  /* * * * * * * * * * * * * *  F U N C T I O N S * * * * * * * * * * * */
  
      function cleanQuery($string)
      {
        $string = trim($string);
        $string = strip_tags($string); // remove any html/javascript.
  
        if(get_magic_quotes_gpc())  // prevents duplicate backslashes
        {
          $string = stripslashes($string);
        }
        if (phpversion() &gt;= '4.3.0')
        {
          $string = mysql_real_escape_string($string);
        }
        else
        {
          $string = mysql_escape_string($string);
        }
        return $string;
      }
  
  
  function bq_handle_shorthand($text) {
      $text = preg_replace("/ \+/", " and ", $text);
      $text = preg_replace("/ -/", " not ", $text);
      return $text;
  }
  
  
  function bq_explode_respect_quotes($line) {
          $quote_level = 0;   #keep track if we are in or out of quote-space
          $buffer = "";
  
          for ($a = 0; $a &lt; strlen($line); $a++) {
                  if ($line[$a] == "\"") {
                          $quote_level++;
                          if ($quote_level == 2) { $quote_level = 0; }
                  }
                  else {
                          if ($line[$a] == " " and $quote_level == 0) {
                                  $buffer = $buffer . "~~~~";   #Hackish magic key
                          }
                          else {
                                  $buffer = $buffer . $line[$a];
                          }
                  }
  
          }
  
      $buffer = str_replace("\\", "", $buffer);
  
          $array = explode("~~~~", $buffer);
          return $array;
  }
  
  
  function bq_make_subquery($fields, $word, $mode) {
  
      if ($mode == "not") {
          $back = " LIKE '%$word%'))";
      }
      else {
          $back = " LIKE '%$word%')";
      }
  
      if ($mode == "not") {
          $front = "(NOT (";
          $glue = " LIKE '%$word%' AND ";
      }
      else {
          $front = "(";
          $glue = " LIKE '%$word%' AND ";
      }
  
      $text = str_replace(" ", $glue, $fields);
      $text = $front . $text . $back;
  
      return $text;
  }
  
  
  
  function bq_make_query($fields, $text) {
  
      $text = strtolower($text);
  
  
      $text = bq_handle_shorthand($text);
  
  
      $wordarray = bq_explode_respect_quotes($text);
  
      $buffer = "";
      $output = "";
  
      for ($i = 0; $i&lt;count($wordarray); $i++) {
          $word = $wordarray[$i];
  
          if ($word == "and" or $word == "not" and $i &gt; 0) {
              if ($word == "not") {
  
  
                  $i++;
                  if ($i == 1) {   #invalid sql syntax to prefix the first check with and/or/not
                      $buffer = bq_make_subquery($fields, $wordarray[$i], "not");
                  }
                  else {
                      $buffer = " AND " . bq_make_subquery($fields, $wordarray[$i], "not");
                  }
              }
              else {
                  if ($word == "and") {
                      $i++;
                      if ($i == 1) {
                          $buffer = bq_make_subquery($fields, $wordarray[$i], "");
                      }
                      else {
  
                          $buffer = " AND " . bq_make_subquery($fields, $wordarray[$i], "");
                      }
                  }
                  else {
                      if ($word == "and") {
                          $i++;
                          if ($i == 1) {
                              $buffer = bq_make_subquery($fields, $wordarray[$i], "");
                          }
                          else {
  
                              $buffer = " AND " . bq_make_subquery($fields, $wordarray[$i], "");
                          }
                      }
                  }
              }
          }
          else {
              if ($i == 0) {  # 0 instead of 1 here because there was no conditional word to skip and no $i++;
                  $buffer = bq_make_subquery($fields, $wordarray[$i], "");
              }
              else {
                  $buffer = " AND " . bq_make_subquery($fields, $wordarray[$i], "");
              }
          }
          $output = $output . $buffer;
      }
      return $output;
  }
  
  
  
  function bq_simple ($return_fields, $tables, $check_fields, $query_text) {
  
  
      $return_fields = str_replace(" ", ", ", $return_fields);
      $tables = str_replace(" ", ", ", $tables);
  
  
      $query = "SELECT $return_fields FROM $tables WHERE ";
      $query = $query . bq_make_query($check_fields, $query_text);
  
      #
      # Uncomment to debug
      #
  
      return $query;
  }
  
  
  
  ?&gt;
  </code></pre>