//this is my code from class.php
class Functions
{
function getUsers($sex)
{
$stmt = $pdo->prepare('SELECT lname,fname from users WHERE gender = :gender');
$stmt->execute(array(':gender'=>$sex));
foreach($stmt as $row)
{
echo $row['lname'].'-'.$row['fname'];
//this is what i think but i don't need to echo because the echo must be in index.php.What is the right way?
}
}
$function = new Functions();
}
//this is for my index.php
include 'class.php'
$function->getUsers($gender);
//this is what i think but it is probably wrong or incomplete.
foreach(what should i put here?)
{
echo '<li>' names should be here? '</li>'
}
//the output should get all the user based on the gender :(
问题:我如何从我的函数中检索值,因为它的值来自 foreach 并且值的数量不固定?提前致谢 :)