RE: [PHP-DEV] how-to get array[0] and array[name] to actually reference only 1 value?
Also, even though [0] and ['id'] initially contain the same value, they are not bound together in any way. You may be able to accomplish what you desire by using references. (See the manual section on references for more information. ie. $q-data[0]["id"] = $q-data[0][0]; How can I create such a reference in code? Now I'm using zend_hash_index_update and zend_hash_update for $q-data[0][0] and $q-data[0]["id"], but that doesn't create a reference. So how should I code this? Cheerio, Marc. -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] how-to get array[0] and array[name] to actually reference only 1 value?
Well, I guess that hacking the php source would work. :) However, I was just thinking that you Could do something like this: (Note - not tested! :) while (list ($key, $value) = mysql_fetch_array ($result, MYSQL_ASSOC)) { $data[] = $data[$key] = $value; } --zak - Original Message - From: "Marc Boeren" [EMAIL PROTECTED] To: "'Zak Greant'" [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Monday, February 12, 2001 2:25 AM Subject: RE: [PHP-DEV] how-to get array[0] and array["name"] to actually reference only 1 value? not bound together in any way. You may be able to accomplish what you desire by using references. (See the manual section on references for more information. ie. $q-data[0]["id"] = $q-data[0][0]; After looking for references in the php-code, I found something that seems to work ok (zend_assign_to_variable_reference): zval *dummy, *value, **x_ptr, **y_ptr; MAKE_STD_ZVAL(value); ZVAL_LONG(value, 10); ALLOC_ZVAL(dummy); INIT_ZVAL(*dummy); zend_hash_update(return_value-value.obj.properties, "x", sizeof("x"), value, sizeof(zval *), (void **) x_ptr); zend_hash_update(return_value-value.obj.properties, "y", sizeof("y"), dummy, sizeof(zval *), (void **) y_ptr); zend_assign_to_variable_reference(NULL, y_ptr, x_ptr, NULL ELS_CC); This leads me to another question: how do I obtain the x_ptr (from the example) if the zend_hash_update was done elsewhere and no ptr was passed then??? zend_hash_update(return_value-value.obj.properties, "x", sizeof("x"), value, sizeof(zval *), NULL); [...] // How do I get the x_ptr ??? zend_hash_update(return_value-value.obj.properties, "y", sizeof("y"), dummy, sizeof(zval *), (void **) y_ptr); zend_assign_to_variable_reference(NULL, y_ptr, x_ptr, NULL ELS_CC); Cheerio, Marc. -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DEV] how-to get array[0] and array[name] to actually reference only 1 value?
Well, I guess that hacking the php source would work. :) However, I was just thinking that you Could do something like this: while (list ($key, $value) = mysql_fetch_array ($result, MYSQL_ASSOC)) { $data[] = $data[$key] = $value; } I could, but since I'm writing a database abstraction module I'm wrapping the mysql-routines (and other db's as well, but since I just started it's only mysql for now). Anyway, basic functionality (including the references) now works on win, so I'll try and compile it on my Linux-box. Cheerio, Marc. (BTW, why a cc to the bug database?) -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DEV] how-to get array[0] and array[name] to actually reference only 1 value?
What I'm trying to do is get the following php-script to work... (the only thing about this that doesn't work is in the fourth 'echo' line...) $db = dbx_connect("mysql", "localhost", "username", "password"); // works $result = dbx_query($db, "use dbname"); // works $q = dbx_query($db, "select id from tbl"); // works // now I have the results in a 2D array, q-data[row][col] // where col can be either an index or a fieldname echo $q-data[0][0]; // works, displays first returned id, say 17 echo $q-data[0]["id"]; // works, displays first returned id (17) // now I want to change the first returned id... $q-data[0][0] = 12345; // what I want is that the next two lines BOTH reflect the change echo $q-data[0][0]; // works, displays changed id (12345) echo $q-data[0]["id"]; // doesn't work like I would like, still displays first returned id (17) // This is the same behaviour that you get when you use the mysql-functions // directly, so no help there... (you can still combine these functions with the // mysql-functions, if needed, like $fieldtype = mysql_field_type($q-handle, 0); // ) $result = dbx_close($db); // works ( $result = mysql_close($db-handle); works too, BTW ) Currently I don't think this can be done the way I would like it to work. Can anybody contradict me on this? Cheerio, Marc. -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] how-to get array[0] and array[name] to actually reference only 1 value?
This list is for discussing issues that relate to the development of the PHP language. For mailing lists that discuss development with PHP, see www.php.net/support.php Also, even though [0] and ['id'] initially contain the same value, they are not bound together in any way. You may be able to accomplish what you desire by using references. (See the manual section on references for more information. ie. $q-data[0]["id"] = $q-data[0][0]; --zak - Original Message - From: "Marc Boeren" [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, February 09, 2001 2:37 AM Subject: [PHP-DEV] how-to get array[0] and array["name"] to actually reference only 1 value? What I'm trying to do is get the following php-script to work... (the only thing about this that doesn't work is in the fourth 'echo' line...) $db = dbx_connect("mysql", "localhost", "username", "password"); // works $result = dbx_query($db, "use dbname"); // works $q = dbx_query($db, "select id from tbl"); // works // now I have the results in a 2D array, q-data[row][col] // where col can be either an index or a fieldname echo $q-data[0][0]; // works, displays first returned id, say 17 echo $q-data[0]["id"]; // works, displays first returned id (17) // now I want to change the first returned id... $q-data[0][0] = 12345; // what I want is that the next two lines BOTH reflect the change echo $q-data[0][0]; // works, displays changed id (12345) echo $q-data[0]["id"]; // doesn't work like I would like, still displays first returned id (17) // This is the same behaviour that you get when you use the mysql-functions // directly, so no help there... (you can still combine these functions with the // mysql-functions, if needed, like $fieldtype = mysql_field_type($q-handle, 0); // ) $result = dbx_close($db); // works ( $result = mysql_close($db-handle); works too, BTW ) Currently I don't think this can be done the way I would like it to work. Can anybody contradict me on this? Cheerio, Marc. -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]