(PHP) Get repeated data (MySQL) from a value in a dropdown list and show it in a table
I have a file that has a dropdown list with a set of values (matricula) from a database (movimentos) what I want is when I select that value in the dropdown list it searches the database for repeated rows and it shows it in a table with all the data from that value (it's currently 3 columns, "matricula,"marca" and "despesa")
Below is the code I use to get the value from the dropdown list, and this is where I have the problem, I can't get the value from the dropdown list to show the respective rows in the table.
<a href='verificar.dwt.php'>Voltar atrĂ¡s</a>
<div align="center"><?
include 'configmov.dwt.php';
$tableName='movimentos';
$matricula = mysql_real_escape_string($_POST['matricula']);
$sql="SELECT matricula, marca, despesa FROM $tableName WHERE $matricula in (SELECT matricula FROM $tableName GROUP BY $matricula HAVING count($matricula) > 1)";
$result=mysql_query($sql);
$n=1;
echo "Os seus resultados: <p>";
echo "<table border=0>";
echo "<tr bgcolor='#CCFFCC'>";
echo "<td style='width: 100px;'>Matricula</td>";
echo "<td style='width: 100px;'>Marca</td>";
echo "<td style='width: 100px;'>Despesa</td>";
echo "</tr>";
while($row = mysql_fetch_array($result)){
echo "<table border=0>";
echo "<tr bgcolor='#CCCCCC'>";
echo "<td style='width: 100px;'>".$row['matricula']."</td>";
echo "<td style='width: 100px;'>".$row['marca']."</td>";
echo "<td style='width: 100px;'>".$row['despesa']."</td>";
echo "</tr>";
}
?>
</div>
<?php
// close connection;
mysql_close();
?>
I'm around this problem for a while and I did a lot of research before coming here to make this question.
Answer
Solution:
matricula is a field from table, in your post... not a php variable..So you must have : GROUP BY matricula HAVIG count(matricula)
Answer
Solution:
Please make sure you SQL syntax is correct and try this code for making a table from returned database values to make it a single table
Answer
Solution:
First of all.. I think that your syntax is wrong.
Try this one:
In a query you must put the php variables between quotes.
Answer
Solution:
if you are checking for an exact match in Table for the posted value, why cant you use this instead?