Fred007 Fred007 - 3 months ago 9
MySQL Question

Php-Myql: select every row with same specific value

I tried to made an autofilling html table that add or remove its rows with database. But now I need to make that the table will fill in only those rows with specific "Domain" column. For example, I have 3 table rows and in 2 of them, "domain" colum's value is "1" and the third row has "domain" column value of 1. I need to my php code to automatically choose only those rows with "1" value in "Domain" column and ignore the others. So when I add more rows to my database, the html table will only take those rows with 1 specific value.

Code:

<?php

$server = mysql_connect("localhost", "admin", "admin");
$db = mysql_select_db("rpo", $server);
$query = mysql_query("SELECT * FROM suhrn");
?>

<table>
<tr>
<td>Text</td>
<td>Type</td>
<td>Zobrazit</td>
<td>DOMAIN</td>
<td>Comment</td>
</tr>


<?php
while ($row = mysql_fetch_array($query)) {
?>
<tr>
<td> <?php echo $row['Popis']; ?> </td>
<td> <?php echo $row['Typ']; ?> </td>
<td> <?php echo $row['Zobrazit']; ?> </td>
<td> <?php echo $row['Domena']; ?> </td>
</tr>
<?php
}
?>
</table>

Answer

I'm not sure if I understood your problem, but maybe a slight modification to your SQL-Statement should do the trick.

SELECT * FROM suhrn WHERE col_domain = 1;

Hope that helps

Regards