1

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.

4 Answers 4

1

matricula is a field from table, in your post... not a php variable..So you must have : GROUP BY matricula HAVIG count(matricula)

Sign up to request clarification or add additional context in comments.

Comments

1

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

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 "<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>";

}

echo "</table>";

Comments

1

First of all.. I think that your syntax is wrong.

Try this one:

$sql = "SELECT matricula, marca, despesa FROM '$tableName' WHERE '$matricula' in (SELECT matricula FROM '$tableName' GROUP BY '$matricula' HAVING count('$matricula') > 1)"; 

In a query you must put the php variables between quotes.

1 Comment

ive done what you said but it´s still not showing the value from the dropdown list, i may have something wrong
0

if you are checking for an exact match in Table for the posted value, why cant you use this instead?

 $sql="SELECT matricula, marca, despesa FROM ".$tableName." WHERE matricula = '".$matricula."'"; 

3 Comments

Thanks! I did what you said and it did the work!! Man i am so happy! really really thanks, my brain was malfuncting with this one
it was simple SQL, if you want to make the table a single one, make sure you change the table as i have given in my previous answer..
ive changed the table with you´re previous answer and everything works and looks good now! Thanks a lot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.