Display DB data in list form

0

I'm developing a website to make animal donations / adoptions online, but I'm extremely lazy on the subject and my knowledge in PHP is small. For the user to donate an animal (add an ad on the site) he will have to fill out a form containing Ad Title, Ad Description and Animal Image (these three data will be saved in the database). This function is already working, the problem is that I do not know how to display this data on the home screen of the site. I know I should run a "SELECT" command, but I do not know where to put this command, what syntax to insert that SELECT in PHP, and how to insert the select data inside a variable to later display it on the home page. I do not need anything flashy, just something basic to show the image on the homepage (animal list). can anybody help me? Thank you in advance.

    
asked by anonymous 12.12.2017 / 01:39

1 answer

0
<?php
    $conn = new mysqli('localhost','root','','bd'); //configuração do bd
    $sql = $conn->prepare("SELECT algo,algomais from tabela"); //prepara a query
    $sql->execute(); //executa a query
    $rs = $sql->get_result(); //pega o resultado da query
    while ($result = $rs->fetch_assoc() ) { //enquanto tiverem resultados correspondentes da query
        echo "Alguma coisa:".$result['algo']."Alguma coisa a mais".$result['algomais']; //lista os resultados
    }
?>

I do not know how you are doing your site since you did not specify however it is highly recommended to use MySQL or PDO since mysql > have become obsolete in PHP 5.5.

The above example makes use of MySQLi to list something and algomais in the site using echo php

    
12.12.2017 / 02:30