Digital catalog

Asked

Viewed 44 times

-4

`

                            <?php 




                            
                            $result_estoque = "SELECT estoque FROM produto";
                            $resultado_estoque = mysqli_query($conn, $result_estoque);
                            $result_estoque >= 1;
                            if($result_estoque >= 0)
                            echo "<font color=\"#008000\">Disponível</font></b>";
                            elseif($result_estoque <= 0)
                            echo "<font color=\"#FF0000\">Indisponível</font></b>"; 







                    ?></h3>`

I put up my if. I’m assembling a digital catalog that pulls the product information from my database, i would like to know how do I stop instead of showing the quantity of products that have in stock, it show the name Available when have products in stock and unavailable when the stock is zeroed. would like to know how to do that if?

imagem do catalogo
click on the image to view it in its original size

<div class="row">
            <?php while($rows_produtos = mysqli_fetch_assoc($resultado_produtos)){ ?>
                <div class="col-sm-6 col-md-3">
                    <div class="thumbnail">
                        <img src="imagens/produto.jpg" alt="...">
                        <div class="caption text-center">
                            <a href="detalhes.php?id_curso=<?php echo $rows_produtos['id']; ?>"><h3>Produto <br><?php echo $rows_produtos['nome']; ?></h3><h3>Descrição <br><?php echo $rows_produtos['descricao']; ?></h3><h3>R$ <?php echo $rows_produtos['valor_venda']; ?></h3><h3>Código: <?php echo $rows_produtos['codigo']; ?></h3><h3>Estoque: <?php echo $rows_produtos['estoque']; ?></h3></a>

                        

                        </div>
                    </div>
                </div>
            <?php } ?>
        </div>
    </div>

Estrutura da tabela produtos

  • tried as follows $stock = 1; if($stock == 1) echo "Available"; elseif($stock == 0) echo "Unavailable";

  • but to no avail

  • You can edit the question to include the formations you commented on.

  • Which query is performed to generate variable values $rows_produtos = mysqli_fetch_assoc($resultado_produtos) ?

  • include_once("connected.php"); $result_products = "SELECT * FROM products"; $resultado_products = mysqli_query($Conn, $result_products);

1 answer

-1

You can do this if both in the programming language and in the SQL query language.

In SQL:

Select @estoque := 1 as Estoque, 
       IF(@estoque>0, "Disponível", "Indisponível") as Disponibilidade;

Upshot:

Stockpile Availability
1 Available

Observing:

SQL query above just to illustrate. O @estoque of the stretch IF(@estoque>0, "Disponível", "Indisponível") should be replaced by the field in your table.

Read more about the function IF in Mysql

  • in my database I have the Products table and within the products table I have the Stock table, which receives the values defined in the product register. when the value is 0 I want it to show the customer the unavailable information and when the value is greater than 0 he informs the customer that the product is available, I did several tests and still could not apply the IF, remembering that I am beginner! thank you for your attention!

  • How is your initial SQL query? Have you tried applying the IF I mentioned? What is the structure of your table? Edit the question is enter the Table Structures.

  • but it hasn’t worked yet.

Browser other questions tagged

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