Re: Probably very easy to do, but for some reason...



..oO(paulf.johnson@xxxxxxxxx)

For some reason, my brain has gone to mush on a couple of things. Any
help would be appreciated.

I have an array and a field passed into a function (call it $v) which
is a string composed of comma sep values.

What kind of values? Strings? Numbers?

foo = array("one"=>1, "two", "three", "four", "five");
$ex = explode("," $v);
$newtext = "";
foreach ($ex as $e)
{
if ($e != "0")
$newtext .= " : " . $foo[$e];
}

The problem is that $e here is not being interpreted how I'd expect
(I'd assume it to be a number). Do I need to cast $e as an int or is
there something I'm missing?

What do you get and what do you expect from the code above? Please be
more specific with your error descriptions. Additionally your array $foo
looks a bit strange - do a print_r($foo) to see its actual structure. Is
that really what you want?

A related problem comes from an sql query.

mysql_fetch_rows returns an array (bar).

Did you mean mysql_fetch_row()?

I pass this to another
function. Next I try to iterate through.

The array appears to be a 2D array.

mysql_fetch_row() returns a single row, not the entire result set.

Final one - inserting an array into a table. I can't see anything
about this, but if I have an array which marries up exactly with the
fields in a table, can I just use "insert into tablename(*) values
($array) where ID=some_id"?

No. Of course you could write a little helper function that takes such
an array as an argument (preferrably an associative array - using * in
queries is highly unreliable because it doesn't guarantee any order!),
then creates a proper INSERT statement from it and executes it.

Micha
.



Relevant Pages

  • Re: Formatting...
    ... and puts a comma there to show separation. ... "if" statement to search that array and not write it. ... something like if EmailAddr or whatever your using ... Now when I run the script the output is like this: ...
    (microsoft.public.scripting.vbscript)
  • Re: separate cell values with formulas - can this be improved?
    ... It assumes either a comma following the last value, ... first a correction to my original helper column. ... array constant by... ... in the main portion of the invoice I have these two array ...
    (microsoft.public.excel.worksheet.functions)
  • Re: How to best parse a CSV data file and do a lookup in C?
    ... > and build an array for each line seperating on the commas. ... that you either change its type to "static char" (otherwise the ... making fscanfread a maximum number of 128 characters as long ... that must be a comma or a newline. ...
    (comp.lang.c)
  • Re: how to show the fragment of element from array ?
    ... I have problem with 3-dimensional array: ... Regex-en are "greedy", i.e. they try to match as much as possible, so the first \S+ will match everything until the last comma, leaving the rest for the second \S+. ... If you want to stay with a regex, there are two possibilities ... Company Details: http://www.fujitsu-siemens.com/imprint.html ...
    (comp.lang.perl.misc)
  • Re: Modal dialog doesnt threads to sleep in Firefox?
    ... A final comma in an array literal does not imply a following ... Mozilla is correct here and JScript is the ... A software bug is not determined by a personal opinion. ... Given the choice I would have the final comma define an additional ...
    (comp.lang.javascript)