0

I have this function below. It outputs each line of a Mysql DB. Each line is a path to a file.

e.g.

/Volumes/02_SERVER/GRADE/GRADE_10/Test Me/978079 G10 English/downloads/revision-tests

It works fine. But what I want is to make it linkable.

I have tried this sort of thing:

echo "<a file='" . $o . "' ></a>";

But it does not work

All the Code:

<?php
    require_once 'db.php';
    // Output HTML formats
    $html = '<tr>';
    $html .= '<td class="small">nameString</td>';
    $html .= '</tr>';

    // Get the Search
    $search_string = preg_replace("/_-[^A-Za-z0-9]/", " ", $_POST['query']);
    $search_string = $test_db->real_escape_string($search_string);

    // Check if length is more than 1 character
    if (strlen($search_string) >= 1 && $search_string !== ' ') {
        //Insert Time Stamp
        $query = 'SELECT * FROM live_table WHERE name LIKE "%' . $search_string . '%"';
        //Timestamp entry of search for later display
        $time_entry = $test_db->query($time);
        //Count how many times a query occurs
        $query_count = $test_db->query($query_count);
        // Do the search
        $result = $test_db->query($query);
        while ($results = $result->fetch_array()) {
            $result_array[] = $results;
        }

        // Check for results
        if (isset($result_array)) {
            foreach ($result_array as $result) {
                // Output strings and highlight the matches
                $d_name = preg_replace("/" . $search_string . "/i", " <b>" . $search_string . "</b>", $result['name']);
                $d_comp = $result['company'];
                // Replace the items into above HTML
                $o = str_replace('nameString', $d_name, $html);
                // Output it
                echo ($o);
            }
        } else {
            // Replace for no results

            $o = str_replace('nameString', '<span class="label label-danger">No Data Found</span>', $html);
            // Output
            echo($o);
        }
    }
?>
mitkosoft
  • 5,262
  • 1
  • 13
  • 31
user2720970
  • 284
  • 1
  • 3
  • 17

2 Answers2

1

Please give the path like (http://localhost/pagination/) this to your anchor tag so that your included database is accessed and you have got proper resutlt.

dpkrai96
  • 93
  • 1
  • 11
0

The format of a local link in an HTML anchor is

<a href='file://filepath/file.ext'>Description </a>

In your PHP code, change

echo($o);

to

 echo("<a href='file://$o'>$o</a>");
Neil Richins
  • 91
  • 1
  • 4
  • Your code will give big errors. The HTML your outputting is wrong and so is your line of PHP. Watch your quotes and variables inside your echo.. Correct line would be like this: `echo ''.$o.'';` – Huso Apr 07 '16 at 08:13