mysql query select multiple rows where the value of the column is the same

advertisements

i have this table

Column_1        Column_2
1                 value1
2                 value1
3                 value2

My php query is

$query = "SELECT * FROM `table` WHERE `Column_1` = 'value1' ";
print_r($query);

This returns only the 1st row. I am looking to display row 1 and 2. When I run the SQL in phpmyadmin it returns row 1 and 2. However, the php script only returns row 1... I also did an

echo count($query);

But it returns only 1. What am i doing wrong?


$query = "SELECT * FROM `table` WHERE `Column_2` = 'value1' ";
$res = mysql_query($query);
if(mysql_num_rows($res)!=0) {
    while($rowData = mysql_fetch_array($res)) {
        var_dump($rowData);
    }
}

  • Use mysql_num_rows to count number of results.
  • Use mysql_fetch_array or mysql_fetch_assoc to fetch data.