function Gets_comments_array_from_db($type, $thread_comment_id) {
# Sets variable for Query
$The_TYPE = $type;
$Thread = mysql_real_escape_string(intval($thread_comment_id));
# return array query for Further working
return mysql_query("SELECT * FROM `site_comments` WHERE `type`='".$The_TYPE."' AND `thread_comment_id`='".$Thread."'");
}
和
while($comment = mysql_fetch_array(Gets_comments_array_from_db('news', $id)){
echo '11';
}
谢谢! :)
答案 0 :(得分:0)
由于 dbf 表示您在while循环的每次迭代中执行查询。你需要改变这样的代码:
$rs = Gets_comments_array_from_db('news', $id);
while($comment = mysql_fetch_assoc($rs)) {
echo '11';
}
现在,您将获得一次结果,然后在while循环中迭代它们。在循环内部,您还可以使用列名作为数组键来处理值。
while($comment = mysql_fetch_assoc($rs)) {
$field1 = $comment['field1'];
$field2 = $comment['field2'];
$field3 = $comment['field3'];
}
如果你像这样构建你的mysql查询
SELECT Field1, Field2, Field3, Field4 FROM {table} WHERE {where_clause}
你可以像这样在
$rs = Gets_comments_array_from_db('news', $id);
while(list($field1, $filed2, $filed3, $field4) = myslq_fetch_row($rs)) {
// use variables here
}