Select Single Row From MySQLi Using PHP

January 14, 2024


$query = "
SELECT * 
FROM items
WHERE deleted != 'y'
AND item_id = ?
LIMIT 1
";

$stmt = $mysqli -> prepare($query);
$stmt -> bind_param("s", $item_id);
$stmt -> execute();
$result = $stmt -> get_result();

$num_rows = $result -> num_rows;

if ( $num_rows === 0 ) {

echo 'There are no rows';

} else {

$row = $result -> fetch_assoc();

echo $row['item_id'];

}


Comments

There are no comments.


Comment on this Article

Your email address will never be published. Comments are usually approved within an hour or two. (to prevent spam)