nst
02-14-2006, 05:51 PM
Hi,
I have an array inside a function. What is the code in order to make it global?
It's about $stock_symbol[$i].
If I write global $stock_symbol[] it provokes an error.
Thanks.
function insert_data()
{
global $year, $date, $link_id;
$query = "INSERT INTO ref_calendar VALUES (NULL, '$date')";
mysql_query($query, $link_id);
$date_id = mysql_insert_id($link_id);
for($i = 1; $i < $l_count; $i++) {
$stock_symbol[$i] = substr($lines[$i], 0, 5);
$price_date[$i] = substr($lines[$i], 21, 10);
$query = "INSERT INTO stocks(stock_symbol) VALUES ('$stock_symbol[$i]')";
mysql_query($query, $link_id);
$query = "INSERT INTO share_prices VALUES (NULL, $date_id, '$stock_symbol[$i]', '$price_date[$i]')";
mysql_query($query, $link_id);
}
}
I have an array inside a function. What is the code in order to make it global?
It's about $stock_symbol[$i].
If I write global $stock_symbol[] it provokes an error.
Thanks.
function insert_data()
{
global $year, $date, $link_id;
$query = "INSERT INTO ref_calendar VALUES (NULL, '$date')";
mysql_query($query, $link_id);
$date_id = mysql_insert_id($link_id);
for($i = 1; $i < $l_count; $i++) {
$stock_symbol[$i] = substr($lines[$i], 0, 5);
$price_date[$i] = substr($lines[$i], 21, 10);
$query = "INSERT INTO stocks(stock_symbol) VALUES ('$stock_symbol[$i]')";
mysql_query($query, $link_id);
$query = "INSERT INTO share_prices VALUES (NULL, $date_id, '$stock_symbol[$i]', '$price_date[$i]')";
mysql_query($query, $link_id);
}
}