Jump to content

Putting fields into an array


apot

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.