apot Posted October 1, 2007 Share Posted October 1, 2007 im trying to get this function to work. function get_fields() { $result = mysql_db_query($db,"SHOW FIELDS FROM product_type_prices"); $rows = array(); while ($row = mysql_fetch_assoc($result)) { if ($row["Extra"] == "auto_increment") continue; $this_row = $row; if (stripos($row["Type"], "char") !== false) { $this_row["Type"] = "char"; } else if (stripos($row["Type"], "date") !== false) { $this_row["Type"] = "date"; } else if (stripos($row["Type"], "int") !== false) { $this_row["Type"] = "int"; } else if (stripos($row["Type"], "dec") !== false) { $this_row["Type"] = "dec"; } $rows[$row["Field"]] = $this_row; } return $rows; } $fields = get_fields(); echo "<PRE>"; var_dump($fields); echo "</PRE>"; It works when it is not in a function but when in a function returns: array(0) { } Any idea what is happening here? Quote Link to comment https://forums.phpfreaks.com/topic/71402-putting-fields-into-an-array/ Share on other sites More sharing options...
BlueSkyIS Posted October 1, 2007 Share Posted October 1, 2007 for your answer, add or die(mysql_error()): $result = mysql_db_query($db,"SHOW FIELDS FROM product_type_prices") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/71402-putting-fields-into-an-array/#findComment-359369 Share on other sites More sharing options...
apot Posted October 1, 2007 Author Share Posted October 1, 2007 Thanks that showed me that there is no database connection. There is a connection at the beginning of the same script but not in the function. Is this normal do you have to establish a connection within a function? Quote Link to comment https://forums.phpfreaks.com/topic/71402-putting-fields-into-an-array/#findComment-359404 Share on other sites More sharing options...
BlueSkyIS Posted October 1, 2007 Share Posted October 1, 2007 You could try using the external connection by declaring the vars global inside of the function: function xyz () { global $db, $link, $whatever, $vars $youneedfromoutside; } Quote Link to comment https://forums.phpfreaks.com/topic/71402-putting-fields-into-an-array/#findComment-359408 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.