html - Php-Myql: select every row with same specific value

302

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>
867

Answer

Solution:

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

830

Answer

Solution:

Not sure it's exact based on what you wrote, but you could try that :

$query = mysql_query("SELECT * FROM suhrn WHERE Domena=1");

Additionaly, you should stop using mysql_function, and use mysqli or PDO instead.

People are also looking for solutions to the problem: php - Show values of the db in organization with Bootstrap row class for every 3 columns

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.