当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Can I store query result of one field into different variables? if not then what should I do for that?

问题描述:

This code shows the output as subject1 subject2 subject3 subject4 but I want to store that values in different variables (like $s1=[1],$s2[2],$s3[3],$s4[4]) so I and use them in different functions what should I do? can any one help please...

网友答案:
$query = mysql_query("select `subject` from `markssub1` where `sname`='$user' AND `sid`='$id'");

$subjects = [];

while($row = mysql_fetch_array($query))
{
    $subjects[] = $row['subject'];  
}

foreach($subjects as $subject){
    echo $subject . '\n';
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: