I need a help with Php and Mysql

0

I am creating a website / blog in Php, I already did a search system in php and mysql, but I have a doubt, I already researched the subject and do not think, I would like to know, how to return a query in the database in links, for example, I put a field for the user to do a search, and the results come in forms of links, such as post titles, I do not want anyone to make the code for me, just tell me how I can do that.

    
asked by anonymous 02.06.2018 / 03:13

1 answer

4

In a column of a table in the database, save the urls.

In% of query% put it as value of attribute echo of tag href

  

a

Complete example

$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

//$sql = "Sua Query";
$sql = "SELECT * FROM Tabela"; //exemplo
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
  

echo ("<a href='".$row['link']."'>

    }
} else {
    echo "0 results";
}
$conn->close();

Example:

  • Table

  • Result

  • Sourcecode

02.06.2018 / 07:27