Freitag, 10. Jan. 2003 17:01 wrote l0t3k:
> Johannes,
> could you perhaps show a bit of the schema and your expected array
> output in print_r format ?
>
Yes, it comes below and also a solution by me:
So my questions ar now:
1.) Is this ok or make this a lot of memory leaks ?
I hope, in the end of script, the zend engiene freed the lot of arrays,
they ar build in while ....
2.) I'm not sure by using the last argument (1 | NULL) in zend_hash_xxx and
add_assoc_string.
3.) Is there an easy way to build the grow-up strings without memory leaks and
memory waste.
----------------------------------------------
print_r(my_wish_array):
----------------------------------------------
Array
(
[felder] => Array
(
[ObjektLand] => Array
(
[name] => ObjektLand
[type] => text
[value] =>
[checked] => 0
[multiple] => 0
[size] => 0
[minlength] => 1
[maxlength] => 50
[length_e] => Zu viele oder zu wenige Zeichen ...
[icase] => 1
[valid_regex] => ^[a-z]*$
[valid_e] => Falsche Zeichen im Feld Land.
[cols] => 0
[rows] => 0
[wrap] =>
[extrahtml] =>
)
[Bundesland] => Array
(
[name] => Bundesland
[type] => select
[value] =>
[checked] => 0
[multiple] => 0
[size] => 0
[minlength] => 1
[maxlength] => 0
[length_e] =>
[icase] =>
[valid_regex] =>
[valid_e] =>
[cols] => 0
[rows] => 0
[wrap] =>
[extrahtml] =>
[options] => Array
(
[0] => Array
(
[label] => Nordrhein-Westfalen
[value] => NRW
)
[1] => Array
(
[label] => Niedersachsen
[value] => NL
)
[2] => Array
(
[label] => Mecklenburg-Vorpommern
[value] => MVL
)
)
)
)
[text] => Array
(
[ObjektLand] => Array
(
[title] => Land:
[help] => Bitte geben Sie hier das Land ein.
[beschreibung] => Land in dem das Objekt liegt.
)
[Bundesland] => Array
(
[title] => Bundesland:
[help] => Bitte w�hlen Sie das Bundesland aus.
[beschreibung] => Bundesland in dem das Objekt liegt.
)
)
[select] => ObjektLand AS AObjektLand, Bundesland AS ABundesland,
[update_x] => A.ObjektLand = '%s', A.Bundesland = '%s',
[update_y] => AObjektLand, ABundesland,
[fieldlist] => Array
(
[0] => ObjektLand
[1] => Bundesland
)
)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
my solution: (a part):
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
....
while (s_row = mysql_fetch_row(s_mysql_res)) {
zval *field_array, *options_array, *options_value_array, *text_value_array;
if (!strcmp(s_row[1], "select")){
MAKE_STD_ZVAL(options_value_array);
if(array_init(options_value_array) != SUCCESS){
zend_error(E_ERROR, "field_array konnte nicht inizialisiert
werden!");
}
MAKE_STD_ZVAL(options_array);
if(array_init(options_array) != SUCCESS){
zend_error(E_ERROR, "field_array konnte nicht inizialisiert
werden!");
}
snprintf(sql2, 200, "SELECT label_%s, value FROM form_pairs WHERE name
= 'frm_%s'", arg6, s_row[0]);
if (mysql_query(&s_mysql, sql2)){
mysql_fehler(&s_mysql);
RETURN_FALSE;
}
s_mysql_res2 = mysql_store_result(&s_mysql);
if (mysql_errno(&s_mysql) != 0){
mysql_fehler(&s_mysql);
RETURN_FALSE;
} else if (mysql_num_rows(s_mysql_res2) == 0){
/* Fehlerbehandlung keine Optionen angegeben */
} else {
y = 1;
while (s_row2 = mysql_fetch_row(s_mysql_res2)) {
add_assoc_string(options_value_array, "label", s_row2[0], 1);
add_assoc_string(options_value_array, "value", s_row2[1], 1);
zend_hash_next_index_insert(Z_ARRVAL_P(options_array),
&options_value_array, sizeof(zval *), NULL);
}
}
mysql_free_result(s_mysql_res2);
}
MAKE_STD_ZVAL(field_array);
if(array_init(field_array) != SUCCESS){
zend_error(E_ERROR, "field_array konnte nicht inizialisiert werden!");
}
MAKE_STD_ZVAL(text_value_array);
if(array_init(text_value_array) != SUCCESS){
zend_error(E_ERROR, "text_value_array konnte nicht inizialisiert
werden!");
}
pkey = s_row[0];
sprintf(pkeyP, "%s%s", arg7, s_row[0]);
sprintf(pkeyPP, "%s.%s", arg7, s_row[0]);
add_assoc_string(field_array, "name" , pkeyP, 1);
for (z = 1; z < (fields - 3); z++) {
if ( !strcmp(s_row[z], "0" ) || !strcmp(s_row[z], "" ) ){
continue;
}
add_assoc_string(field_array,fieldinfo[z].name , s_row[z], 1);
}
for (z = (fields - 3); z < fields; z++) {
add_assoc_string(text_value_array,fieldinfo[z].name , s_row[z], 1);
}
if (y == 1){
zend_hash_add(Z_ARRVAL_P(field_array), "options" , strlen("options")+1
, &options_array, sizeof(zval *), NULL);
}
add_next_index_string(fieldlist_array, pkeyP , 1);
zend_hash_add(Z_ARRVAL_P(text_array),pkeyP , strlen(pkeyP)+1 ,
&text_value_array, sizeof(zval *), NULL);
zend_hash_add(Z_ARRVAL_P(return_value),pkeyP , strlen(pkeyP)+1 ,
&field_array, sizeof(zval *), NULL);
}
}
mysql_free_result(s_mysql_res);
mysql_close(&s_mysql);
zend_hash_add(Z_ARRVAL_P(return_value),"text" , strlen("text")+1 , &text_array,
sizeof(zval *), NULL);
zend_hash_add(Z_ARRVAL_P(return_value),"fieldlist" , strlen("fieldlist")+1 ,
&fieldlist_array, sizeof(zval *), NULL);
add_assoc_string(return_value, "select", "", 1);
add_assoc_string(return_value, "update_x", "", 1);
add_assoc_string(return_value, "update_y", "", 1);
}
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
--
Thanks
Johannes G. Arlt
[EMAIL PROTECTED]
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php