By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,420 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

simple php question: mysql_fetch_row display array contents

P: n/a
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
Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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 | http://www.wse.jhu.edu/newtnotes/

Jul 16 '05 #2

P: n/a

On 18-Aug-2003, to***@liquidationworld.com (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
www.creative-light.com
Jul 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.