Kan*_*ell 2 php mysql arrays oop foreach
我希望有人可以提供帮助.
我确定它只是一个简单的,我出于某种原因无法解决.
基本上我有一个类来处理我的所有数据库函数(连接,选择,插入,更新).
在select函数中,我返回一个数组.
public function getAll($table, $cols, $where, $limit, $order) {
// Set the query variables
if($cols == '') {
$cols = '*';
}
if($where!='') {
$where = ' WHERE '.$where;
}
if($limit!= '') {
$limit = ' LIMIT '.$limit;
}
if($order!='') {
$order = ' ORDER BY '.$order;
}
// Make the query string
$sql = 'SELECT '.$cols.' FROM '.$table.$where.$order.$limit;
//echo $sql;
// Set the query
$news_qry = mysql_query($sql);
// Set the array
$rows = array();
// Run a loop through the results
while($item = mysql_fetch_object($news_qry))
{
// Add each row to an array.
$rows[] = $item;
}
return $rows;
}
Run Code Online (Sandbox Code Playgroud)
这个功能正常,因为我可以打印一个数组.见下文:
Array ( [Gallery_id] => 1 [Gallery_Name] => Test [Gallery_FolderName] => Test Folder )
Run Code Online (Sandbox Code Playgroud)
但是当我去使用这个对象时 -
$arr_GalleryInfo = $dataObj->getAll('tbl_Gallery', '', '', '', '');
Run Code Online (Sandbox Code Playgroud)
在每个循环中(见下文)我只从数据库中得到结果的第一个字母.
<?php
foreach ($arr_GalleryInfo[0] as $arrGallery)
{
?>
<tr>
<td>
<?php echo $arrGallery['Gallery_Name']; ?>
</td>
<td>
<?php echo $arrGallery; ?>
</td>
<td>
<?php echo $arrGallery; ?>
</td>
</tr>
<?php
}
?>
Run Code Online (Sandbox Code Playgroud)
任何帮助都会很棒.
谢谢.
JK.*_*JK. 10
更换:
foreach ($arr_GalleryInfo[0] as $arrGallery)
{
etc...
Run Code Online (Sandbox Code Playgroud)
有:
foreach ($arr_GalleryInfo as $arrGallery)
{
etc...
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11698 次 |
最近记录: |