aliento Posted July 6, 2008 Share Posted July 6, 2008 I am trying to build an database application. I use the array $fields[] to store the fields of the table, when i use the function into the main content it is ok but into function it doesnt return the fields! The same with the data which i use a multy dimension array $data[$field][$num] . Is it wrong to return an array from a function? Quote Link to comment Share on other sites More sharing options...
papaface Posted July 6, 2008 Share Posted July 6, 2008 Nothing. It must be your code, so show us some. Quote Link to comment Share on other sites More sharing options...
aliento Posted July 6, 2008 Author Share Posted July 6, 2008 function request_data($database,$table) { include 'settings.php'; $fields = request_fields($database,$table); // another function $db = mysql_connect($db_host,$db_user, $db_pass); mysql_select_db($database,$db) or die("Cannot select the database.<br>" . mysql_error()); $sql="SELECT * FROM $table"; $result = mysql_query($sql,$db); while ($row = mysql_fetch_array($result)) for($i=0;$i<count($fields);$i++) { $field_s = $fields[$i]; $data[$field_s][]=$row[$field_s]; } mysql_close; return $data; } Is this possible? (to return an array?) Quote Link to comment Share on other sites More sharing options...
ron8000 Posted July 6, 2008 Share Posted July 6, 2008 This is a function from my DB class that is what you are looking for. <?php public function dbGetFields($table) { $this->error = FALSE; $query = "SHOW COLUMNS FROM ".$this->dbFormat($table); $result = $this->dbQuery($query); if(!$result) { return FALSE; } for($i=0;$i<mysql_num_rows($result);$i++) { $row = mysql_fetch_assoc($result); $fields[$i] = $row['Field']; } return $fields; } ?> Enjoy Let me know if it works! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.