mercredi 17 janvier 2018

Display link with search results

I have a simple search form on my basic page

<form action="../options-search.php" method="GET">
        <input type="text" name="query" />
        <input type="submit" value="Search" />
    </form>

On the ../options-search.php page I have the following code

<?php
$conn = mysqli_connect($hostname, $user, $pass, $dbase);


    $query = $_GET['query']; 
    $min_length = 3;

    if(strlen($query) >= $min_length){ 

        $query = htmlspecialchars($query); 
        $query = mysqli_real_escape_string ($conn, $query);

        $raw_results = mysqli_query($conn, "SELECT * FROM Options WHERE (`options` COLLATE UTF8_GENERAL_CI LIKE '%".$query."%')" );

        if(mysqli_num_rows($raw_results) > 0){ 

            while($results = mysqli_fetch_array($raw_results)){

                echo "<p>".$results['options']."</p>";
            }
        }
        else{ 
            echo "Nothing Found";
        }             
    }
    else{ 
    }
?>

It works perfectly, however, some of the options have links in the database (for more info on the subject). For another page (not relevant here, but I was trying to use that code) I used the following line of code:

$data[] = $row['thumb'] == 'Yes' ? ">> <a href=\"" . $row['link'] . "\"> $row[options]</a>" : ">> $row[options]"    ; 

This works on that page, but I cannot seem to get it added to this part:

echo "<p>".$results['options']."</p>";

So basically, I want the code to figure out if there is a value named "Yes" in the field "thumb". If not, then it only needs to display the $results['options'], but if it is, it needs to add a link to it. (It is the same database.)

I tried the following, but it doesn't work. The page is displayed without any errors, but the link isn't there.

echo "<p>".$results['thumb'] == 'Yes' ? ">> <a href=\"" . $results['link'] . "\"> $results[options]</a>" : ">> $results[options]"."</p>";

I also tried if / else statements, but I kept getting errors.

How can I solve this? Thank you.

Aucun commentaire:

Enregistrer un commentaire