Display BD data in list form

Asked

Viewed 112 times

0

I am developing a site to make donations/adoptions of animals online, but I am extremely lay in 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 show this data on the home screen of the site. I know that I must execute a "SELECT" command, but I don’t know where to put this command, what syntax to insert this SELECT in PHP, and how to insert the select data into a variable to later show it on the home page. I don’t need anything fancy, just something basic to show the image on the home page (animal list). Can someone help me? Thanks in advance.

  • How did you run INSERT? is very similar. You are using PDO? if you are not strongly recommend it. Which version of PHP? put what you’ve done so far makes it easier to help.

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 have not specified but it is very recommended to use Mysqli or PDO since commands mysql_* have become obsolete in PHP 5.5.

The above example makes use of Mysqli to list something and algomals on the site using echo php

Browser other questions tagged

You are not signed in. Login or sign up in order to post.