I have a very basic setup: A table called "elements" and which has columns "positive","negative","type" and I need to select all the elements and loop only through the ones that have a type of "video". Here's what I have now:
require_once 'dbcon.php';
$stmt = $db->prepare("select positive, negative,type from elements");
$stmt->bind_result($pos,$neg$type);
$stmt->execute();
while($stmt->fetch()){
echo $type
}
I've tried with a if($type=='video')
and while(($stmt->fetch()) && ( $type=='video ))
, but I don't get any results back.
So you need to apply WHERE
in query itself:
SELECT `positive`, `negative`, `type` FROM `elements` WHERE `type`='video'