Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to iterate over an array of arrays
    primarykey
    data
    text
    <p>I'm hoping someone can help.</p> <p>I'm sure its just a simple one that I just can't work out for some reason.</p> <p>Basically I have up a class that handles all my database functions (connect, select, insert, update).</p> <p>In the select function I am returning an array.</p> <pre><code>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; } </code></pre> <p>This function is working as I can print an array. See below:</p> <pre><code>Array ( [Gallery_id] =&gt; 1 [Gallery_Name] =&gt; Test [Gallery_FolderName] =&gt; Test Folder ) </code></pre> <p>But when I go to use the object -</p> <pre><code>$arr_GalleryInfo = $dataObj-&gt;getAll('tbl_Gallery', '', '', '', ''); </code></pre> <p>Within the for each loop (see below) I only get the first letter of the result from the database.</p> <pre><code> &lt;?php foreach ($arr_GalleryInfo[0] as $arrGallery) { ?&gt; &lt;tr&gt; &lt;td&gt; &lt;?php echo $arrGallery['Gallery_Name']; ?&gt; &lt;/td&gt; &lt;td&gt; &lt;?php echo $arrGallery; ?&gt; &lt;/td&gt; &lt;td&gt; &lt;?php echo $arrGallery; ?&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; </code></pre> <p>Any help would be great.</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload