473,668 Members | 2,491 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

This should be easy, but...

Hi

I'm trying to build a simple, one-dimensional array of prices, where the key
to each element is the product code.

So I start by executing a select query "SELECT Code, Price FROM Products",
and the results are returned in a two-dimensional array, $data, which I can
loop through like this:

while (list(, $value) = each($data))
{
$code = $value[0];
$price = $value[1];

I would have thought I could build my array here by writing something like:

$command = "\$arr['$code'] = $price;";
exec($command);

But this doesn't work.

Can anyone explain?
Jul 17 '05 #1
3 1343
iuz
Captain Nemo wrote:
Hi

I'm trying to build a simple, one-dimensional array of prices, where the
key to each element is the product code.

So I start by executing a select query "SELECT Code, Price FROM Products",
and the results are returned in a two-dimensional array, $data, which I
can loop through like this:

while (list(, $value) = each($data))
{
$code = $value[0];
$price = $value[1];

I would have thought I could build my array here by writing something
like:

$command = "\$arr['$code'] = $price;";
exec($command);

But this doesn't work.

Can anyone explain?


there are some errors in your code..
if you want an array like this
array(
'code' => 'price'
)
you can do something like this..

while(list($cod e, $value) = mysql_fetch_arr ay($data))
$product[$code] = $value;

--
www.iuz-lab.info
Jul 17 '05 #2
Panic over!

I was confusing the exec() function with the eval() function.
Jul 17 '05 #3
while (list(, $value) = each($data))
{
$code = $value[0];
$price = $value[1];
/*
$command = "\$arr['$code'] = $price;"; // I belive you
// need \ before all $s
exec($command); // you want eval() here
*/
// wouldn't this be a bit more concise:
$arr[$code] = $price; // why all the command and eval hubbaabaloo?
}

or how about this:
foreach ( $data as $values )
{
$arr[$values[0]] = $values[1];
// or if you used mysql_fetch_ass oc or mysql_fetch_arr ay:
// $arr[$values['Code']] = $values['Price'];
}


"Captain Nemo" <Ca*****@NoSpam .com> wrote in message news:<Hj******* *********@text. news.blueyonder .co.uk>...
Hi

I'm trying to build a simple, one-dimensional array of prices, where the key
to each element is the product code.

So I start by executing a select query "SELECT Code, Price FROM Products",
and the results are returned in a two-dimensional array, $data, which I can
loop through like this:

while (list(, $value) = each($data))
{
$code = $value[0];
$price = $value[1];

I would have thought I could build my array here by writing something like:

$command = "\$arr['$code'] = $price;";
exec($command);

But this doesn't work.

Can anyone explain?

Jul 17 '05 #4

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

Similar topics

19
1520
by: Canon EOS | last post by:
Hi, I am really new in .net and pocket PC development. My background are purely C/C++/VC++. Have developed on Mobile Java for a year and felt completely insecure with it because all codes can easily uncompiled. And it is why I am trying on .net for smartphone and PocketPC devices.
2
1804
by: Hal Vaughan | last post by:
I'm self taught and most of what I've been working on for the past several years has been entirely in Perl and Java. I've noticed that I can code about 5 times faster in Perl than Java, in part because I feel like whenever I want to do something in Java, I have to create an object, do a few preperatory things, then do what I need, but in Perl, I just call the routine. Java, however, does much better at cross platform apps, especially if...
13
1475
by: Ghislain Tanguay | last post by:
I have a compiled vb.net app and I want to give the user a choice to launch it from the start line command and pass it a parameter or not. How can I do that in my code? Is it possible? Ex. : MyApp.exe "Go"
6
2291
by: Martin Bootsma | last post by:
I have a C question, which looks very easy, but no one here seems to know an easy answer. I have a function "powell" (from Numerical Recipes) which takes an argument of the type "double (*f)(float)" But I want to be able to pass a
1
2577
by: NevilleDNZ | last post by:
Hi, Apologies first as I am not a unicode expert.... indeed I the details probably totally elude me. Not withstanding: how can I convert a binary string containing UTF-8 binary into a python unicode string? cutdown example: $ cat ./uc.py #!/usr/bin/env python imported="\304\246\311\231\316\257\316\271\303\222
6
7086
cjbrx3115
by: cjbrx3115 | last post by:
Hey everyone, I just bought a new Windows Vista (Home Premium) computer. My old computer, a Windows XP Professional, had all of my old documents, spreadsheets, etc. I was planing on using the Easy Transfer on my new machine, and using an Ethernet cable to transfer the files. When I launched the Windows Vista Easy Transfer, I went through the process and followed all the directions. But when I had to run the program on my old computer, when I...
2
2755
by: Ben | last post by:
I'm looking for a web application framework with a good interface to PostgreSQL. The app I'm developing is relatively simple, but I'm new to coding, so it needs to be easy. What I'm making is a wiki-like system that could be thought of as similar to MediaWiki, but with each word editable separately - ie. edit locks would be one word at a time.
59
2504
by: Kevin Walzer | last post by:
From the introduction to PyObjC, the Python-Objective-C bridge on Mac OS X: "As described in Objective-C for PyObjC users the creation of Objective-C objects is a two-stage process. To initialize objects, first call a class method to allocate the memory (typically alloc), and then call an initializer (typically starts with init). Some classes have class methods which perform this behind the scenes, especially classes that create cached,...
2
2690
by: Dr. Colombes | last post by:
Is there an easy scientific graphics (plotting) package for Python 2.5.1 running on Ubuntu Linux 7.1 ("Gutsy Gibbon")? A few years ago I used PyLab (a MatLab-like plotting module for Python) on a Windows machine, but I don't know if there is a similar easy-to-install-and-use Python 2.5.1-compatible graphics package for Ubuntu Linux 7.1? Thanks for any suggestions.
14
1815
by: Grant | last post by:
I've seen a couple of articles on the internet that VB.NET applications can be decompiled very easy. For those who have had experience with this, is it true? What steps can be taken to avoid this? I am using VB.NET Express but am willing to buy something (within reason) to prevent easy decompiling. Any suggestions are much appreciated.
0
8381
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8586
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7401
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6209
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4205
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4380
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2026
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1786
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.