This should be easy, but...

Ask a Question related to PHP Development, Design and Development.

  1. #1

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



    Captain Nemo Guest

  2. Similar Questions and Discussions

    1. Help please...It must be very easy
      Hello I?m having problems in making AV presence component to connect without using simple connect...I need to broadcast video from a webcam to...
    2. Do you know CF? This one should be easy
      I'm relatively new to CF and programming so bear with me on this one. If I was receiving form data with input field names such as form.option1,...
    3. Easy question = easy answer?
      Well, so I'm pretty new with Freehand, at the mo running with MX and havin' a problem (not big, but anyway)... I'm creating some cards and they...
    4. probably easy for you, but . . .
      Over the years, believe it or not, I have never used Multiple select boxes. Now, can someone tell me where I can see some sample code for how to get...
    5. Easy Question/Easy Answer
      Ok, this is all i want to know how to do, i made a text link, now when someone rolls over it with their pointer i want it to change color. Simple?
  3. #2

    Default OK - Mystery solved!!!

    Panic over!

    I was confusing the exec() function with the eval() function.


    Captain Nemo Guest

  4. #3

    Default Re: This should be easy, but...

    "Captain Nemo" <Captain@NoSpam.com> wrote in message
    news:CaU7d.1716$xb.1032@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);
    >
    eval (as you mentioned in your followup) is not needed either. Simply use:

    $arr[$code]=$price;

    by using eval, you appear to be attempting to force the subscript to be a
    literal value and that isn't necessary.

    - Virgil


    Virgil Green Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139