Mysql dosen't select all when using SELECT function

My code looks like this:

$sql = "SELECT `sw1`, `sw2`, `sw3`, `sw4`, `fb1`, `fb2`, `fb3`, `fb4`, `bew1`, `bew2`, `bew3`, `bew4` FROM `reg` WHERE `id` = ".$id." ORDER BY `id` ASC LIMIT 0, 30 ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        foreach($row as $x => $x_value) {
             echo "Key=" . $x . ", Value=" . $x_value;
             echo "<br>";
        }
    }
}

      

The sw2

available data, but not shown.
When I tried to update the data, the data in the db was not changed.
$id

is correct.
other data from the table can be read.

+3


source to share


3 answers


This code works great:



$sql = "SELECT * FROM `reg` WHERE `id` = ".$id." ORDER BY `id` ASC LIMIT 0, 30 ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    $row = $result->fetch_assoc();
    print_r($row);
}

      

+1


source


Try echoing the request. same problem follows trying to change Where 'id' = "$ id" to Where 'id' like "$ id"



0


source


You don't need quotes:

$sql = "SELECT sw1, sw2, sw3, sw4, fb1, fb2, fb3, fb4, 
bew1, bew2, bew3, bew4 
FROM reg WHERE id = $id";

      

0


source







All Articles