Hi, Having some problems with multi-dimentional arrays. I am creatng an array using some database data, and adding stuff like an image tag, and hyperlink. Then passing this to another function that creates an Html table from an array.
Here is the function to create the table from an array, seems to work fine. //------------------------------------------------------------------------- // Builds transparent table from array function trans_table_array ($array, $bodyfontcolor = "", $headerfontcolor = "") { global $theme_bodyfontcolor, $theme_headerfontcolor; // Defined in a theme file // Poputlate with theme colors if called without specifying if ($bodyfontcolor == "") $bodyfontcolor = $theme_bodyfontcolor; if ($headerfontcolor == "") $headerfontcolor = $theme_headerfontcolor; $content = "<table align=center border=0>\n"; foreach ($array as $rowkey => $colkey) { $content .= "<tr align='center'>"; foreach ($colkey as $value) { if ($rowkey=="0") // Treat first row as column names { $content .= "<th><div align=\"center\"><font color=\"$headerfontcolor\">" . $value . "</font></div></th>\n"; } else { $content .= "<td>"; if (!isset($value)) //test for null value {$content .= "NULL";} else {$content .= "<div align=\"center\"><font color=\"$bodyfontcolor\">" . $value . "</font></div>";} $content .= "</td>\n"; } } $content .= "</tr>\n"; } $content .= "</table>"; return $content; } //------------------------------------------------------------ I use this function to get the whole database results into an array, passing the result of a query //------------------------------------------------- function mysql_fetch_array_r($result, $fetch = MYSQL_BOTH) { $row_counter = 0; while ($row = mysql_fetch_array($result,$fetch)) { $whole_result[$row_counter] = $row; $row_counter++; } return $whole_result; } //---------------------------------------------- Then I am trying to build a table with 3 pictures per row. $query = "Select * from picture"; $result = mysql_query($query) or die (mysql_error()); // Returns array with entire contents of query $whole_result = mysql_fetch_array_r($result); $col_key = 0; foreach ($whole_result as $rowkey => $colkey) { $table_string = "<a href='delete_pic.php?product_id= {$whole_result[$rowkey]['product_id']}'> <img src='{$whole_result[$rowkey]['path']}' width='185' height='150' ><br> {$whole_result[$rowkey]['path']}</a>"; $table_array[$rowkey][$col_key] = $table_string; // 3 $table_string per row in table if ($col_key< 2) { $col_key++; } else { $col_key=0; } } echo trans_table_array($table_array); The above is not populating the array correctly. It results in one $table_string per row instead of column. Am I just simply making a logic error. This multi-dimentional array stuff is confusing, been struggling with this for hours. Does anyone else have a simpler way of seperating logic, and html? Thanks for any help.