Re: [PHP] Associative array issues with loading values after initialization
I found the issue. The whitespace in between $list as $k => $V was all not truly whitespace. Gotta love BBEdit... Thomas Bolioli wrote: I hav ebeen able to track down that this is the part not working. It throws a parse error: PHP Parse error: syntax error, unexpected T_VARIABLE on the line where the foreach loop starts. function dropbox_from_list(&$list, $selected_index){ foreach ($list as $k => $v) { if (strcmp($selected_index, $k) == 0) { $select = ' SELECTED'; } else { $select = ''; } print "$v"; } } b wrote: Thomas Bolioli wrote: I should add, it is not working with this funciton, which could be the source of the issue. function dropbox_from_list($list, $selected_index){ while ($nex = next($list)) { I'd use foreach() here and avoid next(). At least, reset the array first. And maybe pass the array by reference: function dropbox_from_list(&$list, $selected_index) { foreach($list as $k => $v) { $k = key($nex); if (strcmp($selected_index, $k) == 0) { $select = ' SELECTED'; } else { $select = ''; } print("value='".$k."'".$select.">".$nex[$k].""); } } Maybe you should also add what it is that's "not working". Thomas Bolioli wrote: The below function is not working. function crm_get_country_list(){ global $dbh; $result = mysql_query("SELECT * FROM countries ORDER BY pk_country_id ASC", $dbh) or die(mysql_error()); $country_list = array(' ' =>' '); Are you starting with an empty key & value so that you'll have an empty option in your select list? Why not just print an empty one? while ($row = mysql_fetch_assoc($result)){ $country_list[$row['pk_countryID']] = $row['country_name']; } return $country_list; } Start with the obvious: what does $country_list contain when it's returned? Again, some details about what you're getting would go a long way toward getting some advice. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Associative array issues with loading values after initialization
I hav ebeen able to track down that this is the part not working. It throws a parse error: PHP Parse error: syntax error, unexpected T_VARIABLE on the line where the foreach loop starts. function dropbox_from_list(&$list, $selected_index){ foreach ($list as $k => $v) { if (strcmp($selected_index, $k) == 0) { $select = ' SELECTED'; } else { $select = ''; } print "$v"; } } b wrote: Thomas Bolioli wrote: I should add, it is not working with this funciton, which could be the source of the issue. function dropbox_from_list($list, $selected_index){ while ($nex = next($list)) { I'd use foreach() here and avoid next(). At least, reset the array first. And maybe pass the array by reference: function dropbox_from_list(&$list, $selected_index) { foreach($list as $k => $v) { $k = key($nex); if (strcmp($selected_index, $k) == 0) { $select = ' SELECTED'; } else { $select = ''; } print("".$nex[$k].""); } } Maybe you should also add what it is that's "not working". Thomas Bolioli wrote: The below function is not working. function crm_get_country_list(){ global $dbh; $result = mysql_query("SELECT * FROM countries ORDER BY pk_country_id ASC", $dbh) or die(mysql_error()); $country_list = array(' ' =>' '); Are you starting with an empty key & value so that you'll have an empty option in your select list? Why not just print an empty one? while ($row = mysql_fetch_assoc($result)){ $country_list[$row['pk_countryID']] = $row['country_name']; } return $country_list; } Start with the obvious: what does $country_list contain when it's returned? Again, some details about what you're getting would go a long way toward getting some advice. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Associative array issues with loading values after initialization
This came straight out of the docs and it doesn't even work. It throws PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING on the line "'one' => 1," What is wrong with how I am trying to do this loop?? Thanks, Tom $a = array( 'one' => 1, 'two' => 2, 'three' => 3, 'seventeen' => 17 ); foreach ($a as $k => $v) { echo "\$a[$k] => $v.\n"; } Thomas Bolioli wrote: I should add, it is not working with this funciton, which could be the source of the issue. function dropbox_from_list($list, $selected_index){ while ($nex = next($list)) { $k = key($nex); if (strcmp($selected_index, $k) == 0) { $select = ' SELECTED'; } else { $select = ''; } print("".$nex[$k].""); } } Thomas Bolioli wrote: The below function is not working. function crm_get_country_list(){ global $dbh; $result = mysql_query("SELECT * FROM countries ORDER BY pk_country_id ASC", $dbh) or die(mysql_error()); $country_list = array(' ' =>' '); while ($row = mysql_fetch_assoc($result)){ $country_list[$row['pk_countryID']] = $row['country_name']; } return $country_list; } I know how to write this in perl but for some reason, when I write it in PHP it doesn't work. In perl it would be (roughly): function crm_get_country_list(){ global $dbh; $result = mysql_query("SELECT * FROM countries ORDER BY pk_country_id ASC", $dbh) or die(mysql_error()); my %country_list; while ($row = mysql_fetch_assoc($result)){ $country_list[$row['pk_countryID']] = $row['country_name']; } return \%country_list; } What am I doing wrong here? Thanks in advance, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Associative array issues with loading values after initialization
I should add, it is not working with this funciton, which could be the source of the issue. function dropbox_from_list($list, $selected_index){ while ($nex = next($list)) { $k = key($nex); if (strcmp($selected_index, $k) == 0) { $select = ' SELECTED'; } else { $select = ''; } print("".$nex[$k].""); } } Thomas Bolioli wrote: The below function is not working. function crm_get_country_list(){ global $dbh; $result = mysql_query("SELECT * FROM countries ORDER BY pk_country_id ASC", $dbh) or die(mysql_error()); $country_list = array(' ' =>' '); while ($row = mysql_fetch_assoc($result)){ $country_list[$row['pk_countryID']] = $row['country_name']; } return $country_list; } I know how to write this in perl but for some reason, when I write it in PHP it doesn't work. In perl it would be (roughly): function crm_get_country_list(){ global $dbh; $result = mysql_query("SELECT * FROM countries ORDER BY pk_country_id ASC", $dbh) or die(mysql_error()); my %country_list; while ($row = mysql_fetch_assoc($result)){ $country_list[$row['pk_countryID']] = $row['country_name']; } return \%country_list; } What am I doing wrong here? Thanks in advance, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Associative array issues with loading values after initialization
The below function is not working. function crm_get_country_list(){ global $dbh; $result = mysql_query("SELECT * FROM countries ORDER BY pk_country_id ASC", $dbh) or die(mysql_error()); $country_list = array(' ' =>' '); while ($row = mysql_fetch_assoc($result)){ $country_list[$row['pk_countryID']] = $row['country_name']; } return $country_list; } I know how to write this in perl but for some reason, when I write it in PHP it doesn't work. In perl it would be (roughly): function crm_get_country_list(){ global $dbh; $result = mysql_query("SELECT * FROM countries ORDER BY pk_country_id ASC", $dbh) or die(mysql_error()); my %country_list; while ($row = mysql_fetch_assoc($result)){ $country_list[$row['pk_countryID']] = $row['country_name']; } return \%country_list; } What am I doing wrong here? Thanks in advance, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] quick php for perl coder question
I want to return an array from a function. I have this: return array($found, $username, $email, $nickname); as my code. I have a bug in the code and I am not sure where yet. Should the above statement with this: array($vars); $vars = function($type, $abc, $xyz); $found = $vars[0]; $username = $vars[1]; $email = $vars[2]; $nickname = $vars[3]; on the other end work? If so, then the bug is somewhere else. Thanks in advance, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] direct access to file uploads
I am new to PHP and am trying to get access to files that are uploaded. I have RTFM ;-) and have noticed that PHP writes the file to disk in a temporary location and provides a method/class with all of the information needed to access it. I am loading (PDF's) into a binary field in mySQL and find it rather inefficient to have the file written to disk, and then have it read off and then written back into the db which is ultimately written to disk. Is there a way I can get direct access to the file as it comes in. I noticed a user comment on predefined vars page mentioned $RAW_POST_DATA (or something like that) but no info on how to address it. Is that my answer and what do I do from there? It also seems to be depricated and I do not want to use something that will disappear soon. Thanks in advance, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] bcmod()
The docs (see below) for bcmod() are rather skimpy. Does anyone have a clue as to how it works. Basically I want to do this (below code). PS: I am new to PHP but not to programming in general. Tom $i = 1; while (something true){ $modulus = the_modulus_of($i / 4); // does php do % instead of /? if($modulus == 0){ do_this_this_time(); } $i++; } *bcmod* (PHP 3, PHP 4 ) bcmod -- Get modulus of an arbitrary precision number Description string bcmod ( string left_operand, string modulus) Get the modulus of the left_operand using modulus. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] str_replace() problems actually *_replace() problems tobe
Thanks, I was so hung up on the regex that I failed to spot the (obscenely) obvious through my tunnel vision. Sometimes a fresh pair of eyes makes all the difference. Anyhow, the understatement of the day award goes to Lars for "There's only one thing you didn't try..." ;-) Thanks again, Tom Lars Torben Wilson wrote: On Mon, 2003-06-16 at 11:49, Thomas Bolioli wrote: I am a perl/java/c++ programmer who is doing something in php and have run accross something I am stumped with. I am trying to replace carriage returns with or tags (p's in groups of two and br's for any unmatched cr's). I have tried all of the *_replace() functions including string_*, ereg_* and preg_*. None have worked the way they seem to should. Note, I am a perl programmer and preg_replace() did not work while a test perl script did. I have tried multiple forms of patterns from "\r\n" to "\n" to "\r" to "/\r?\n/ei" (in the *reg_* functions). I even took code verbatim from examples in the docs to no avail. I have included the entire block of code (and mysql_dump output) since there is something I have apparently not done right and it may not be in the pattern matches. Thanks in advance, Tom Hi Tom, There's only one thing you didn't try...see below: *The offending code:* }elseif($_REQUEST['add']){ $desc = $_REQUEST['description']; str_replace("\r\n\r\n", "", $desc); str_replace("\r\n", "", $desc); You need to assign the result of the replacement to something before you can use it; arguments are not modified in place. So something like this: $desc = str_replace("\r\n\r\n", "", $desc); $desc = str_replace("\r\n", "", $desc); This change shouild be all you need. However, if you want to be able to accept input from other than windows users, you can do the whole thing with strtr(). I haven't tested with preg_replace(), but I suspect that using regexps for this would be overkill. $trans = array("\n\n" => '', "\n" => '', "\r\r" => '', "\r" => '', "\r\n\r\n" => '', "\r\n" => ''); $desc = strtr($desc, $trans); Hope this helps, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Emptying the browser cache
There is no way to do this in any programming language since it is not part of the http spec. There may be som client side vb hack that someone knows that works on IE for Windows but I doubt it. It is not very secure to allow web sites to control your browser's cache. Try looking into expire times on your responses (http feature) so your content does not get cached in the first place. Note that if you are paying for bandwith and have caps you will be mighty surprised next time the bill comes around. Caches are a good thing. Tom Don wrote: Hi, Is the a PHP command that will empty the browser's current cache? Thanks, Don -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] str_replace() problems actually *_replace() problems to be more accurate
I am a perl/java/c++ programmer who is doing something in php and have run accross something I am stumped with. I am trying to replace carriage returns with or tags (p's in groups of two and br's for any unmatched cr's). I have tried all of the *_replace() functions including string_*, ereg_* and preg_*. None have worked the way they seem to should. Note, I am a perl programmer and preg_replace() did not work while a test perl script did. I have tried multiple forms of patterns from "\r\n" to "\n" to "\r" to "/\r?\n/ei" (in the *reg_* functions). I even took code verbatim from examples in the docs to no avail. I have included the entire block of code (and mysql_dump output) since there is something I have apparently not done right and it may not be in the pattern matches. Thanks in advance, Tom *The offending code:* }elseif($_REQUEST['add']){ $desc = $_REQUEST['description']; str_replace("\r\n\r\n", "", $desc); str_replace("\r\n", "", $desc); $result = mysql_query('INSERT INTO hr_listings (title,description,location,end_date,posting_date) VALUES("'.$_REQUEST['title'].'","'.$desc.'","'.$_REQUEST['location'].'","'.$_REQUEST['end_date'].'", NOW())',$db) or trigger_error("MySQL error nr ".mysql_errno().": ".mysql_error()); *Output of mysql_dump showing the \r\n's going in* INSERT INTO hr_listings VALUES (15,'test',5,'2003-06-16','2003-09-11',NULL,'This is one line\r\nThis is the next\r\n\r\nThis is another paragraph\r\n\r\n'); INSERT INTO hr_listings VALUES (16,'test2',1,'2003-06-16','2004-09-11',NULL,'Thi s is one line\r\nThis is the next\r\n\r\nThis is another paragraph\r\n\r\n'); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php