473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

Hi,

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.

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?

A related problem comes from an sql query.

mysql_fetch_rows returns an array (bar). I pass this to another
function. Next I try to iterate through.

The array appears to be a 2D array.

for ($m = 0; $m < count($bar); $m++)
{
for ($i = 0; $i < sizeof($bar[0]); $i++)
{
echo $bar['0']['3']; // works fine
echo $bar['0'][$i]; // doesn't work - same reason as above I'd
imagine
}
}

Probably a really simple answer, but one I can't figure out.

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"?

Thanks for helping me on these!

TTFN

Paul
--
Sie können mich aufreizen und wirklich heiß machen!
Jul 29 '08 #1
1 1587
Hi,

On Jul 29, 1:58 pm, paulf.john...@gmail.com wrote:
Hi,

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.

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?
You may want to do $e !== '0' to match the value and type exactly
without type conversions. You might occasionally get slightly
unintuitive results with regular comparison, e.g.: The expression
('-000' == '0') is true.

Try print_r on $e to check the unexpected result.
A related problem comes from an sql query.

mysql_fetch_rows returns an array (bar). I pass this to another
function. Next I try to iterate through.

The array appears to be a 2D array.

for ($m = 0; $m < count($bar); $m++)
{
for ($i = 0; $i < sizeof($bar[0]); $i++)
{
echo $bar['0']['3']; // works fine
echo $bar['0'][$i]; // doesn't work - same reason as above I'd
imagine
}

}

Probably a really simple answer, but one I can't figure out.

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"?
You can use MDB2_AUTOQUERY_INSERT to compose and execute a DML
statement from a value array.
Thanks for helping me on these!

TTFN

Paul
--
Sie können mich aufreizen und wirklich heiß machen!
Jul 29 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Eric | last post by:
Hey Everyone.. I have a form that has approximately 7 text fields and 1 checkbox. Generally when this form is submitted(to itself BTW) it works fine, however, when the checkbox is only field...
3
by: Andy Visniewski | last post by:
Should be easy, but I've been trying to figure this out for about half an hour with no luck. There is a table 'Cybex' which has all the Cybex products we sell, and a table 'Datasheets' which...
6
by: malcolm | last post by:
How does one get the primary key of the row that is joined in via a group by aggregate clause when the aggregate is not performed on the primary key? For example, Person table ( PersonID...
7
by: Bastard_Toadflax | last post by:
I'm making a database for a work project, and am having some difficulties (note: I am at the novice end of the MS Access users spectrum). Basically, what I have to do is make a list of managers in...
4
by: Dino M. Buljubasic | last post by:
I dont know much about threads, so please be easy on explaining me this one. How do I stop a thread completelly (kill it)? What happens with a thread that has been started but not killed? ...
6
by: johan.ekman | last post by:
I found a function in our code with a similar principle as: const char* MyString() const { return "Hello!"; } I believe this function is wrong because "Hello" string would be allocated...
2
by: Stephan Zaubzer | last post by:
Hi all, I encountered a problem with NumericUpDown yesterday and managed to reproduce the error with a very easy examle. I have a Windows Application with only one Form, which contains only one...
14
by: Naraendirakumar R.R. | last post by:
I have a client in the healthcare industry who would prefer to store the connection string in a centralized location in their Active Directory repository. Has anybody done this? What has your...
1
by: Paul F. Johnson | last post by:
Hi, 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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.