Re: Probably very easy to do, but for some reason...
- From: Michael Fesser <netizen@xxxxxx>
- Date: Tue, 29 Jul 2008 22:00:16 +0200
..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
.
- References:
- Probably very easy to do, but for some reason...
- From: paulf . johnson
- Probably very easy to do, but for some reason...
- Prev by Date: Re: else or elseif?
- Next by Date: Re: phpmyadmin configuration
- Previous by thread: Probably very easy to do, but for some reason...
- Next by thread: Re: Probably very easy to do, but for some reason...
- Index(es):
Relevant Pages
|