1
I have two table, Products and Orders.
I need to create a combobox
for products and when the user choose a product, the page has to display all orders related to the product, if I choose another product have to change orders.
I’m thinking of using a Select from the product table to generate the products and then pick up the selected product id and make a select with the orders table.
Ex.:
Produto: Detergente
button: Gerar relatório
Pedido|Quantidade
0123 | 2 und
0258 | 100 und
Code below:
Produto:<SELECT NAME="produto" required="1" onchange="geratabela()">
<option>Selecione...</option>
<?php
$conexao = mysql_connect("localhost","root","usbw");
if (!$conexao) die ("Erro de conexão com localhost, o seguinte erro ocorreu -> ".mysql_error());
mysql_select_db('Varejo', $conexao);
$query1 = "SELECT * FROM produto ORDER BY cod_prod, nome ASC";
$q1 = mysql_query($query1);
while($dados = mysql_fetch_array($q1))
{
?>
<option value="<?=$dados['cod_prod'] ?>">
<?=$dados['nome'] ?>
</option>
<?php
}
?>
</SELECT><br><br>
<?
function geratabela() {
ini_set( 'display_errors', true );
error_reporting( E_ALL );
$conexao = mysql_connect("localhost","root","usbw");
if (!$conexao) die ("Erro de conexão com localhost, o seguinte erro ocorreu -> ".mysql_error());
mysql_select_db('Varejo', $conexao);
$cod_prod = $_GET["cod_prod"];
$sql = "SELECT * FROM pedido where cod_prod=$cod_prod";
$q = mysql_query($sql);
//tabela com os dados
}
?>
What do you already have? Your problem is in select or combo box ? Or both?
– Guerra
Use Ajax, use select onchange or button onclick to query by ajax...
– Mayron Ceccon
@War actually I have only the screen mounted but I’m thinking of logic so I asked why I’m not very good at programming.
– Rich
@Mayronceccon Thanks I will search on the internet, you have some reference site ?
– Rich
@Gustavob if you are using Jquery http://api.jquery.com/jquery.ajax/ or only JS http://www.w3schools.com/ajax/ and to create table http://www.arquivodecodigos.net/dicas/javascript-howto create a tag- list
– Mayron Ceccon
@Mayronceccon Thanks for your help!
– Rich
@Mayronceccon I generated an Ajax code in the notepad(I left the note at home), I will leave it along with the pegunta.
– Rich