simple php question: mysql_fetch_row display array contents

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

  1. #1

    Default simple php question: mysql_fetch_row display array contents

    I am trying to do something in PHP that I thought would be fairly easy
    but has become rather troublesome.

    I'm trying to retrieve a list of numbers from a MySQL database and
    display the contents in a comma delimited string if there is more than
    one element. My problem is that the first element of the array is
    displaying but not any of the others and I can't figure out why.


    $count_lot = 0;
    while ($row = mysql_fetch_row($sql_lot_num_result))
    {
    $lot_num_array[$count_lot] = $row[$count_lot];
    echo "<p>\$lot_num_array[$count_lot] is:
    $lot_num_array[$count_lot]<br />";
    echo "\$count_lot is: $count_lot</p>";

    $count_lot++;
    }

    // if there is more than 1 element in the array then separate them
    with a comma and space
    if ($count_lot == 1)
    {
    $lot_num_string = "$lot_num_array[0]";
    }
    else
    {
    $lot_num_string = implode(", ", $lot_num_array);
    }

    echo "<p>\$lot_num_string is: $lot_num_string</p>";

    ---

    The result is:

    $lot_num_array[0] is: 0111
    $count_lot is: 0

    $lot_num_array[1] is:
    $count_lot is: 1

    $lot_num_array[2] is:
    $count_lot is: 2

    $lot_num_string is: 0111, ,

    ---

    Why is only the first element displaying but not the rest?

    Tony W.
    tonyw(no_spam)@liquidationworld.com
    Tony W. Guest

  2. Similar Questions and Discussions

    1. simple question about passing array to document
      Hi.I have a question I was hoping someone could help me with. I have created a simple page - page1.mxml. In that page I have an unnamed...
    2. Simple Display Question
      Hello all- This query works below, but it displays only one record at a time. It displays a random image each time. How can I make it display two...
    3. Simple go to frame (contents of field) script
      Hi, I'm having a problem with one of my scripts and I can't figure it out. I have it set so that the I have a object on stage that, when...
    4. simple array question?
      On 12-Aug-2003, "Randell D." <you.can.email.me.at.randelld@yahoo.com> wrote: http://www.php.net/manual/en/function.list.php -- Tom...
    5. Simple Array question
      Hi, If i am posting something like this from a form: <input type=checkbox name='id' value=3> <input type=checkbox name='id' value=4> How do i...
  3. #2

    Default Re: simple php question: mysql_fetch_row display array contents

    On Mon, 18 Aug 2003 09:44:31 -0700, Tony W. wrote:
    > I am trying to do something in PHP that I thought would be fairly easy but
    > has become rather troublesome.
    <snip!>

    There are a bunch of potential problems with your code, but I am too beat
    right now to clarify. Sorry. I probably shouldn't even have responded at
    all. I know I would find it annoying if someone responded to *me* with
    this sort of answer...

    i'll post a real answer later...
    --
    Jeffrey D. Silverman | jeffrey AT jhu DOT edu
    Johns Hopkins University | Baltimore, MD
    Website | [url]http://www.wse.jhu.edu/newtnotes/[/url]

    Jeffrey Silverman Guest

  4. #3

    Default Re: simple php question: mysql_fetch_row display array contents


    On 18-Aug-2003, [email]tonyw@liquidationworld.com[/email] (Tony W.) wrote:
    > I'm trying to retrieve a list of numbers from a MySQL database and
    > display the contents in a comma delimited string if there is more than
    > one element. My problem is that the first element of the array is
    > displaying but not any of the others and I can't figure out why.
    >
    >
    > $count_lot = 0;
    > while ($row = mysql_fetch_row($sql_lot_num_result))
    > {
    > $lot_num_array[$count_lot] = $row[$count_lot];
    The index to $row should be the column name or index, but not $count_lot
    > echo "<p>\$lot_num_array[$count_lot] is:
    > $lot_num_array[$count_lot]<br />";
    > echo "\$count_lot is: $count_lot</p>";
    >
    > $count_lot++;
    > }
    >
    (snip)


    --
    Tom Thackrey
    [url]www.creative-light.com[/url]
    Tom Thackrey 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